javascript - Playwright Test Running Twice Even with Worker Set to 1 - Stack Overflow

admin2025-05-01  0

I'm facing an issue where my Playwright test runs twice, even though I've configured the workers option to 1 in my Playwright config. Below is a snippet of my configuration:

timeout: 20 * 60 * 1000,
/* 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 ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See /docs/test-reporters */

Here’s an example of my test structure:

test.describe("First Step", () => {
  test.beforeAll(async () => {
    // Setup code
  });

  test("Single test", async () => {
    // Test code
  });

  test.afterAll(async () => {
    // Teardown code
  });
});

However, when I run this single test, it shows the following in the console: Running 2 tests using 1 worker

Even though I only have one test defined, Playwright identifies it as two tests.

What I've Tried Ensured the workers option is set to 1 in the configuration. Verified the test structure to confirm there's only one test present. Consulted ChatGPT, but the suggestions didn’t resolve the issue. Goal I need my test to execute only once, regardless of the worker count or configuration.

Has anyone encountered a similar issue? If so, how did you resolve it?

I'm facing an issue where my Playwright test runs twice, even though I've configured the workers option to 1 in my Playwright config. Below is a snippet of my configuration:

timeout: 20 * 60 * 1000,
/* 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 ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */

Here’s an example of my test structure:

test.describe("First Step", () => {
  test.beforeAll(async () => {
    // Setup code
  });

  test("Single test", async () => {
    // Test code
  });

  test.afterAll(async () => {
    // Teardown code
  });
});

However, when I run this single test, it shows the following in the console: Running 2 tests using 1 worker

Even though I only have one test defined, Playwright identifies it as two tests.

What I've Tried Ensured the workers option is set to 1 in the configuration. Verified the test structure to confirm there's only one test present. Consulted ChatGPT, but the suggestions didn’t resolve the issue. Goal I need my test to execute only once, regardless of the worker count or configuration.

Has anyone encountered a similar issue? If so, how did you resolve it?

Share Improve this question edited Jan 3 at 7:12 VLAZ 29.2k9 gold badges63 silver badges85 bronze badges asked Jan 2 at 14:48 Md Shahnawaz HussainMd Shahnawaz Hussain 1 3
  • 3 Please add full config, with projects section and your laucnh command if it's not npx playwright test – unickq Commented Jan 2 at 14:50
  • 2 This works fine for me. Please show the files your test command is matching (showing your dir tree and full command is good, as requested). – ggorlen Commented Jan 3 at 4:56
  • 2 Does your playwright config have to projects defined? If so, that will do run the same test twice unless the second project matches tests differently. – AutomationAndy Commented Jan 3 at 11:15
Add a comment  | 

1 Answer 1

Reset to default 0

I had similar issue today while doing playwright training course...my tests were running twice! It took me sometime before to realise I had 2 'chromium' settings under projects (probably bad copy-paste

转载请注明原文地址:http://anycun.com/QandA/1746112511a91842.html