microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
67.11k stars 3.69k forks source link

[Docs]: How to write isolated playwright tests against a real database #33699

Open nodefir opened 1 day ago

nodefir commented 1 day ago

Page(s)

https://playwright.dev/docs/next/browser-contexts

Description

When writing playwright tests against a local database (i.e. a postgres server with a database named your_app_test), there does not seem to be anywhere online that walks one through writing transactional tests that will not leak data during parallelization. All I have been able to come across is information on fixture data, but what about data created by the test itself?

I have gone down the rabbit hole of trying to recreate the seamless system testing (end-to-end testing) provided by Rails, which is able to spin up a test server and run tests in parallel without having to worry about data collisions.

Approaches I have tried thus far:

How can I achieve a similar workflow to Rails system tests, where I can create data (directly in the test or by clicking around in my app) in a test database without worrying about other tests creating similar data? Is this out of scope for playwright?

For what it's worth, I am using prisma and Next.js.