You can manually run an auth.setup
file in Playwright by following these steps:
Open your playwright.config.ts
and find the projects
array. Look for the project with the auth.setup
file. Temporarily remove or comment out this project. This prevents it from running automatically before each test. Don't forget to save your changes!
// playwright.config.ts
module.exports = {
// ...
projects: [
// Comment out or remove the setup project
// {
// name: 'setup',
// testMatch: '**/auth.setup.ts',
// },
// ...
],
};
To manually run the auth.setup
file, open a terminal, navigate to your project directory, and run the following command:
npx playwright test --project=setup
Replace setup
with the name of your setup project if it's different. This command runs only the setup project, allowing you to perform authentication steps without running any tests.
The setup script will authenticate and save its state as specified in your code (e.g., saving cookies and local storage snapshot). The authenticated state will be stored in a designated location (e.g., 'playwright/.auth/user.json'
).
After manually running the setup script, revert back to including or uncommenting the original setup project in your playwright.config.ts
. This ensures that authentication is automatically performed before each test as intended. Don't forget to save your changes!
Remember, this guide is based on configuring global setups using Playwright's projects array. If you have additional specific requirements or constraints, you may need to adjust these steps accordingly.
If you still have questions, please ask a question and I will try to answer it.
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].