Rayrun
← Back to videos

Playwright Fixtures | POM | Playwright Tutorial - part 35

In this video, with the help of playwright fixtures, we are going to reduce the page object model complexity.

In this video, Kaushik demonstrates how to convert a script using the Page Object Model into a script using fixtures. He begins by showing a side-by-side comparison of the two scripts, highlighting the differences in code length and complexity. He then proceeds to explain the steps to convert the script into the fixture version.

First, he creates a file called "base pages.ts" where he imports all the necessary pages and common functions. He then uses the "test" fixture to create a generic code block where he declares the objects for the different pages. He demonstrates how to use the "use" fixture to create the objects and pass the "page" object to the constructor of each page.

Kaushik also mentions that the objects can be created in any order depending on the specific needs of the test cases. He suggests grouping related objects together to improve code readability.

He then demonstrates how to write the test cases using the objects created from the fixture. He shows how to import the "test" fixture and the "expect" function. He gives an example of a test case that clicks on the login link on the header page, enters the email address, and expects a certain result. He shows how to use the "before each" hook to load the URL before each test.

Kaushik concludes the video by mentioning the benefits of using fixtures. He explains that fixtures eliminate the need to import and create objects in every test file, making the code more concise and maintainable. He encourages viewers to practice using fixtures to become comfortable with this approach.

Related Videos

#16 - ARIA and how Playwright is making use of it to identify UI controls?
#16 - ARIA and how Playwright is making use of it to identify UI controls?
Create feature, steps & config | Playwright & Cucumber - Typescript | Part 1
Create feature, steps & config | Playwright & Cucumber - Typescript | Part 1
Getting Started with Playwright and VS Code
Getting Started with Playwright and VS Code
Working with multiple elements in Playwright Test (NodeJS)
Working with multiple elements in Playwright Test (NodeJS)
TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].