← Back to Discord Forum

Run a setup file manually

Hello all!

I’m working on creating authentication for different types of users.

I have an auth.setup file which is set in the config projects array. However, I only want this setup to run on a manual command and not before all the test get ran each time since I will just use the storage before the tests anyway.

Basically I just want those session storages to get manually generated once and that’s it.

Any recommendations on the best way to solve this?

Thanks in advance.

This thread is trying to answer question "How can I manually run an auth.setup file that is set in the config projects array, instead of it running before each test?"

0 replies


Manually Running an Auth Setup File in Playwright

You can manually run an auth.setup file in Playwright by following these steps:

Step 1: Update Your Configuration

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',
    // },
    // ...

Step 2: Manually Run the Setup File

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').

Step 3: Revert Your Configuration

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.

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 luc@ray.run.