microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.77k stars 3.58k forks source link

[BUG] test.afterAll will return error if test.skip at the last test #21363

Closed xyngfei closed 1 year ago

xyngfei commented 1 year ago

System info

Source code

or

Test file (self-contained)

import { test } from "@playwright/test";

test.describe.serial("demo", () => {
  test.beforeEach(async ({ page }) => {
    await page.goto("https://demo.applitools.com/index_v2.html");
  });

  test.afterAll(async ({ page }, testInfo) => {
    console.log("test: " + testInfo.title.indexOf("@api"));
    await page.close();
  });

  test("111 @demo", async ({}) => {
    console.log("111 test");
  });

  test("222 @demo", async ({}) => {
    console.log("222 test");
  });

  test.skip("333 @demo", async ({}) => {
    console.log("333 test");
  });
});

Steps

Expected

It should skip the test without any issue

image

Actual

image

pavelfeldman commented 1 year ago

As stated in the error message, you error is that the { page } fixture is used in afterAll. Each test has its own page, so you don't need to close it after all. afterAll can't have any pages, because it runs after all tests.

If you are looking for a serial mode where the page is reused (anti-pattern), you should copy the example from https://playwright.dev/docs/next/test-retries#reuse-single-page-between-tests. Notice that page fixture is not used there.

pavelfeldman commented 1 year ago

Closing as per above, please feel free to open a new issue if this does not cover your use case.