From the course: Playwright Essential Training: Abstractions, Fixtures, and Complex Scenarios

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Overview of Playwright fixtures

Overview of Playwright fixtures

- [Instructor] The first time I saw a fixture in Playwright, I thought, wait, how does this even work? Fixtures are a lot like black magic. At their core, test Fixtures are used to establish the environment for each test, giving the test everything it needs and nothing else. Fixtures are a lot like the previous abstractions we've discussed, data factories and helper functions. But fixtures are first-class citizens, which gives you even lower level hooks into the Playwright test code base. Actually, all the Playwright test is built on the concept of test fixtures. Some of these examples include page, context, browser, and request, some of which we've used. The magic happens behind the scenes. When you request a fixture in your test, Playwrights Test Runner automatically initializes it, injects it where needed, and tears it down when it's done. The real power of fixtures comes from their flexibility. You can even override built-in fixtures or create your own custom ones. Fixtures have a…

Contents