From the course: Playwright: Design Patterns

Unlock this course with a free trial

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

Fixture scope and isolation

Fixture scope and isolation

- [Instructor] Let's explore the difference between two fixer scopes in Playwright, task scope and worker scope. These scopes control how and when fixtures are created, which impacts how state is managed across your test. So let's start by importing test and renaming it as base from playwright/test. Then I'm going to create a global variable called counter, and we will use this counter within our fixtures. So let's create a fixture now. So constant test is equal to base.extend. And in this base.extend, I will create a fixture called counterFixture. And if you remember, array is used to pass in fixture options, so the first thing is the fixture itself. And we will have the callback function. After this, we have got... We'll just increment the counter. So the global variable, which is counter, I'm going to just increment that. And let's pass in that counter value. Now we need to pass in an option. So the option is scope, and the scope is worker. So here we have created a fixture with a…

Contents