From the course: Playwright: Design Patterns

Unlock this course with a free trial

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

Creating custom fixtures

Creating custom fixtures

- [Instructor] You have already seen an example of using built-in fixtures. So in this video we'll explore how to create custom fixes in playwright. Custom fixes help automate specific tasks like login, making your test suite more maintainable. To create a custom fixture, we extend the default test object in playwright with custom functionality. So here's how we do it. So import, test, and we will rename this test as base and we'll import expect from playwright test. Now we'll create a new test object, which will extend the default playwright. Test. And we'll write, we'll create a new fixture here. So test data is sync and use. The first argument is an object that could contain other fixtures you want to depend on, but here it is empty. The second argument is use, a callback function provided by playwright, which allows you to expose fixtures, data in this case, to the test. So I'm going to create data here, email test edit example.com, and a password pass 1, 2, 3. Now the callback…

Contents