playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: expose router fixtures to "normal" tests (not component)

Open Tallyb opened this issue 1 year ago • 2 comments

🚀 Feature Request

The newly router fixture allows setting multiple handlers for page router request. However, it is limited to component testing only. is there are specific limitation it is limited to CT?

Example

We have routes to external systems in e2e that we want to mock (mostly due to charges imposed by the external system). Having them easily mocked can help in e2e tests and not just in component.

Motivation

can be useful for e2e tests as well.

Tallyb avatar Aug 07 '24 07:08 Tallyb

@Tallyb Thank you for trying the router fixture! It is currently experimental, so we are not bringing it yet to e2e tests.

Could you please explain why would you want it for e2e? Note that you can call page.route() as many times as you'd like, with the same effect as you'd call router.route(). Are you after the MSW-style syntax? Anything else?

dgozman avatar Aug 08 '24 06:08 dgozman

one thing I can think of is that since this is a fixture, and assume my goto is also a fixture, I can now "enforce" the order between the fixtures.

Tallyb avatar Aug 20 '24 12:08 Tallyb

I would also greatly enjoy this feature. The main goal is to reuse my MSW handlers that I already have for most of my routes while E2E testing, but I would like the ability to update specific routes on a test-by-test basis by modifying my MSW routes at runtime. Currently I have to save the msw worker object onto window and then call evaluate to get access to it. It's not easy to work with.

Alternatively, I would be fine just modifying individual tests using page.route if it would intercept the msw worker calls.

aaronschwartz avatar Mar 15 '25 02:03 aaronschwartz