Rayrun
← Back to Discord Forum

Ignore "test results" from auth.setup.ts?

philipfong.posted in #help-playwright
Open in Discord

The playwright docs recommend using auth.setup.ts as mentioned here: https://playwright.dev/docs/auth#basic-shared-account-in-all-tests

This is working fine for me: Set a storage state for my tests via the UI if the storage state is missing. Then playwright moves onto the other tests under the /tests folder

I'm finding that because this "setup" function is essentially also a test, it is making it's way into my playwright reports as a "pass/fail".

Worse yet, when sharding tests across multiple jobs, these "setup" functions that are being recognized as tests are also making it into the playwright report multiple times, for as many shards that exist.

Is there a way to have these setup function not get reported?

This thread is trying to answer question "Is there a way to prevent setup functions from being reported in playwright reports?"

0 replies

Answer

Sure, you can prevent setup functions from appearing in Playwright reports. You'll need to use project dependencies in your playwright.config.ts file.

First, define a project that runs before all others. This is where you'll set up your global actions. Here's how you do it:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'setup',
      testMatch: /global.setup\.ts/,
    },
    // Other projects
  ],
});

Next, make sure other projects depend on this setup project. This way, they'll run only after the setup project has finished. Here's how:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'setup',
      testMatch: /global.setup\.ts/,
    },
    {
      // Other project configuration
      dependencies: ['setup'],
    },
  ],
});

By doing this, only specific projects will run the global setup code in global.setup.ts. Others won't, and so it won't appear in their reports. This gives you more control over what's reported in Playwright.

Remember, with project dependencies, you can decide which projects run the global setup code. This way, you can prevent it from appearing in reports for other projects.

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].