Rayrun
← Back to Discord Forum

playwright.config.js not running setup

So I think I have everything setup correctly in the config but when I go to run all my tests the auth-setup.js is not getting run first. Any thoughts?

const { defineConfig, devices } = require("@playwright/test");
const dotenv = require('dotenv')

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
dotenv.config();

/**
 * @see https://playwright.dev/docs/test-configuration
 */
const config = {
  testDir: "./kuvaApp/tests",
  timeout: 30000 * 4,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 10000,
  },
  /* Run tests in files in parallel */
  fullyParallel: false,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  use: {
    headless: true,
    baseURL: process.env.url,
    trace: "retain-on-failure",
    screenshot: "only-on-failure",
  },
  reporter: [
    ["list"],
    ["html", { open: "never" }],
    ["junit", { outputFile: "results.xml" }],
  ],

  /* Configure projects for major browsers */
  projects: [
    {
      name: "setup",
      testDir: "./auth-setup.js",
      testMatch: "auth-setup.js",
    },
    {
      name: "chromium",
      dependencies: ["setup"],
      use: {
        ...devices["Desktop Chrome"],
        storageState: "./playwright/.auth/loginUserAuth.json",
      },
    },
  
module.exports = defineConfig(config)

This thread is trying to answer question "Why is auth-setup.js not running first and why is the baseurl not found despite being correctly set up in the config?"

4 replies

Try this instead:

testMatch: /auth-setup\.js/,

-> no testDir and a regex so it matches every path.

Still no dice

For some reason its not finding the baseurl either and I updated it to the actual url

When I try to run any test I get an error ```Error: page.goto: Protocol error (Page.navigate): Cannot navigate to invalid URL =========================== logs =========================== navigating to "/", waiting until "load" ============================================================

2 |
  3 | test('login to kuva app', async ({ page }) => {
> 4 |   await page.goto('/')
    |              ^
  5 |   await page.waitForURL('**/kuva')
  6 |   expect(page.getByAltText('autotest')).toBeVisible()
  7 | });

    at C:\Users\Nate\Documents\testAutomation\KuvaPlaywright\kuvaApp\tests\login.spec.js:4:14

1 failed KuvaPlaywright\kuvaApp\tests\login.spec.js:3:1 › login to kuva app ─────────────────────────────```

Related Discord Threads

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