In this video, we'll show you how to re-use authentication with Playwright dependencies, making your testing process more efficient and streamlined. Playwright is a powerful automation library for Node.js that allows you to automate tasks and interactions with web applications.
In this video, Jared from Commit Quality demonstrates how to convert an old Global Setter into a test using Playwright's dependency functionality. This functionality was added in version 1.31, so make sure your Playwright test version is at least 1.31 or higher before proceeding.
A GitHub repository is available to clone, providing the same setup as shown in the video. The project's setup includes a simple test navigating to the Commit Quality demo website, a global setup for logging in and storing state in a JSON file, and a Playwright config file.
To convert the Global setup to the new dependency functionality, follow these steps:
login
and pass the page
fixture.page
fixture takes care of that functionality.globalSetup
attribute.
b) Move the storageState
attribute from the top-level use
statement to the specific project (in this case, Chromium).
c) Add a new project named setup
with a testMatch
pointing to the Global setup.ts file.
d) Add the dependencies
attribute/functionality to the Chromium project.After these changes, running the test should execute the setup code, followed by the actual test. This method allows for a cleaner code organization and easier debugging with trace files generated for both the setup and test files.
Once you've updated to version 1.32, you can use the new UI watch mode feature to view your dependency setups and tests in the Playwright Test UI tool. This offers a convenient way to run tests and debug them.
As always, feel free to ask any questions or share feedback in the comments section, and don't forget to like and subscribe!
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].