valendres / playwright-msw

A Mock Service Worker API for Playwright
MIT License
168 stars 24 forks source link

Mocking request and not just page #74

Open thetif opened 1 year ago

thetif commented 1 year ago

I am using Playwright for my API testing as well as e2e. Could you please add the ability to mock the request object inside the test, and not just the page object? That way I can use my msw to mock external calls, like those to s3. With the way it is set up now, the mocking never gets hit and the call goes through to s3.

valendres commented 11 months ago

Hey @thetif, thanks for the suggestion and my apologies for taking so long to respond!

I'm very interested in your suggestion about enhancing the ability to mock the request object within tests, especially for scenarios like mocking external calls to services like s3. This seems like a valuable feature for those using Playwright for both API and e2e testing.

To make sure I fully understand your needs, could you provide a bit more detail? Are you looking to mock static resources that are loaded during page initialization, or is there a different aspect of request mocking that you're focusing on? I haven't personally tackled this specific challenge yet.

Also, do you know if Playwright currently supports this kind of functionality? Any insights or examples you could share would be greatly helpful. Based on this information, we can explore how it might be integrated into playwright-msw.

thetif commented 11 months ago

I'm sorry, it's been a while since I posted this so I'm having trouble remembering the exact issue. I believe the issue is that I couldn't bypass actual calls to aws with msw in the API tests. I had to do a workaround and set up storageStates in playwright so that we could just avoid it altogether. That workaround might just be good enough. I haven't worked on that project in almost 2 months now, so I'm not entirely sure.

On Sat, Dec 9, 2023 at 1:58 AM Peter Weller @.***> wrote:

Hey @thetif https://github.com/thetif, thanks for the suggestion and my apologies for taking so long to respond!

I'm very interested in your suggestion about enhancing the ability to mock the request object within tests, especially for scenarios like mocking external calls to services like s3. This seems like a valuable feature for those using Playwright for both API and e2e testing.

To make sure I fully understand your needs, could you provide a bit more detail? Are you looking to mock static resources that are loaded during page initialization, or is there a different aspect of request mocking that you're focusing on? I haven't personally tackled this specific challenge yet.

Also, do you know if Playwright currently supports this kind of functionality? Any insights or examples you could share would be greatly helpful. Based on this information, we can explore how it might be integrated into playwright-msw.

— Reply to this email directly, view it on GitHub https://github.com/valendres/playwright-msw/issues/74#issuecomment-1848270841, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAPKOUM2KL3AN5BOLH34UDYIQDYTAVCNFSM6AAAAAA32DURLWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBYGI3TAOBUGE . You are receiving this because you were mentioned.Message ID: @.***>

--

Tiffany Forkner (she/her) Software Engineer

email @.*** cell 678-999-7657 main 410.394.9600 <410-394-9600> office 8 Market Place #200, Baltimore https://maps.google.com/?q=8+Market+Place+%23304,+Baltimore&entry=gmail&source=g

fearless.tech http://fearless.tech/ | What we do https://fearless.tech/work/services | Join our team https://fearless.tech/careers