← Back to Discord Forum

Set up msw in Python API

Hey new here,

Currently I'm working on the UI side of a python DS/ML library. To save time I scrap the backend API of the python API and automatically create a mock-service-worker with msw.

This allows me to reuse it everywhere in dev. When comes the time for e2e tests, I turn off mocking and run the tests on the real backend.

I am considering moving to playwright because (1.) the setup for cypress in CI is not easy , (2.) everybody in the company know pytest and python at an advanced level, while I'm the only one with extensive JS/TS experience.

I would like to register my mock service worker from the Python side of playwright. But I haven't found how yet?

I would be ok with a setup in TS/JS as long as the tests are written in Python,

I'm not sure how to do this?

This thread is trying to answer question "How to register a mock service worker from the Python side of Playwright?"

2 replies

I'm thinking maybe instead of solving it inside playwright, I can maybe:

This would allow me to benefit from my automatically generated mocks while allowing me to override from the pw route API (as msw won't be even present on the web app)

Yup the above work!

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.