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
66.43k stars 3.63k forks source link

[Bug]: Trace network showing duplicate requests when using beforeAll/afterAll #33106

Open jeremy-daley-kr opened 1 week ago

jeremy-daley-kr commented 1 week ago

Version

1.47.2

Steps to reproduce

Run this simple test with the --trace=on flag, so you can see the trace network requests:

import { expect, Page, test } from '@playwright/test';

test.describe('POC', async () => {
  let page: Page;

  test.beforeAll(async ({ browser }) => {
    page = await browser.newPage();
    // Intercept to see a specific request. Should only log once.
    await page.route(/redirection\.js/, async (route) => {
      console.log(route.request().url());
      await route.continue();
    });
    await page.goto('https://playwright.dev');
  });

  test.beforeEach(async () => {
    await page.goto('https://google.com/');
  });

  // Removing this makes only 2x duplication, instead of 3x
  test.afterAll(async () => {
    await page.close();
  });

  test('should work', async () => {
    await expect(page).toHaveTitle(/[a-z]/);
  });
});

Expected behavior

Trace network requests should match the intercepted requests logged... only 1.

Actual behavior

All trace network requests appear to be tripled, even though the intercepted console logs in the test show just one. I don't believe the requests are actually firing 3 times... it just appears that way.

Image

Additional context

No response

Environment

System: OS: macOS 14.4.1 Memory: 80.97 MB / 16.00 GB Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 3.6.1 - ~/.nvm/versions/node/v18.17.1/bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm Languages: Bash: 3.2.57 - /bin/bash npmPackages: playwright: 1.47.2 => 1.47.2 playwright-lighthouse: ^4.0.0 => 4.0.0

mxschmitt commented 1 week ago

I can repro. More minimal repro:

import { Page, test } from '@playwright/test';

test.describe('POC', async () => {
  let page: Page;

  test.beforeAll(async ({ browser }) => {
    page = await browser.newPage();
  });

  test('should work', async () => {
    await page.goto('https://playwright.dev');
  });

  // This results in the duplication
  test.afterAll(() => {});
  test.afterAll(() => {});
  test.afterAll(() => {});
  test.afterAll(() => {});
});

Good: 1.45.0

Bad: 1.46.0

diff: https://github.com/microsoft/playwright/compare/1b4d9003c63ad91b38b42b255759345a8d28d91c...37ffbd757e732b52c3497ff65009fbe3a5743df5