Playwright Test is based on the concept of the test fixtures. Test fixtures are used to establish environment for each test, giving the test everything it needs and nothing else.
In this video, Jared from commit quality provides an informative guide on how to implement test fixtures in Playwright, a JavaScript library used for browser automation. He first gives a clear explanation of what fixtures are - they are intended to establish an environment for individual tests, containing everything the test requires and nothing superfluous.
The tutorial starts with Jared explaining the different built-in fixtures provided by Playwright; these include browser, context, page, browser name and request. With the help of a hands-on demonstration, he shows how to create a setup for a test using these components individually and without fixtures, which demonstrates how complicated and untidy the code looks without them.
After that, he introduces the concept of transforming the same tests by incorporating fixtures which cleans up the test code by handling the setup and tear-down processes in the background, without explicit calls from the developer. This results in a more efficient, maintainable, and tidy codebase.
Next, Jared demonstrates using the ‘request’ fixture to make HTTP requests and showcases the use of the browser name fixture to output the name of the browser being used. Following that, he develops another test, this time using fixtures right from the start, to highlight how cleaner and quicker the process becomes when fixtures are employed.
The video concludes with a summary of the benefits of using fixtures in Playwright for more efficient and streamlined testing. Jared hints at future videos to delve into more advanced topics, such as creating your own fixtures or configuring existing ones to further customize your testing workflow.
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].