Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Trace is not being retained on test failure in before/after hooks. #28733

Closed
surajsahu8 opened this issue Dec 20, 2023 · 4 comments · Fixed by #29181
Closed

[BUG] Trace is not being retained on test failure in before/after hooks. #28733

surajsahu8 opened this issue Dec 20, 2023 · 4 comments · Fixed by #29181
Assignees
Labels

Comments

@surajsahu8
Copy link

System info

Playwright Version: [v1.38.x, v1.39.x, v1.40.0, v1.40.1, v1.41.0-alpha-nov-23-2023]
Operating System: Ubuntu
Browser: [Chromium]
Node Version: v18.17.1
Browser Image: mcr.microsoft.com/playwright:v<playwright-version>-focal

Source code

// playwright.config.ts

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

export default defineConfig({
  globalSetup: require.resolve('./global-setup'),
  globalTeardown: require.resolve('./global-teardown'),
  outputDir: 'test-results',
  testDir: 'tests',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  timeout: process.env.TEST_TIMEOUT,
  expect: { timeout: 15 * 1000 }, // 15 seconds
  retries: process.env.RETRIES,
  workers: process.env.WORKERS,
  repeatEach: process.env.REPEAT_EACH,

  use: {
    baseURL: process.env.BASE_URL,
    headless: true,
    viewport: { width: process.env.BROWSER_WIDTH, height: process.env.BROWSER_HEIGHT },
    ignoreHTTPSErrors: true,
    defaultBrowserType: 'chromium',
    screenshot: 'only-on-failure',
    trace: 'retain-on-failure',
    video: 'retain-on-failure',
    permissions: ['clipboard-read', 'clipboard-write'],
    storageState: <customized storage state>,
    actionTimeout: process.env.ACTION_TIMEOUT,
    navigationTimeout: process.env.NAVIGATION_TIMEOUT,
  },

  reporter: [
    ['list'],
    [
      'allure-playwright',
      {
        suiteTitle: true,
        environmentInfo: {
          NODE_VERSION: process.version,
          OS: process.platform,
          IS_HEADLESS: process.env.HEADLESS,
          BROWSER: process.env.BROWSER,
        },
      },
    ],
    ['json', { outputFile: 'test-results.json' }],
    ['junit', { outputFile: 'test-results.xml' }],
    ['html', { open: 'never' }],
    ['./summaryReporter'],
  ],

  projects: [
    {
      name: 'chromium',
      use: '{ browserName: 'chromium' }',
    },
  ],
});

Steps

  • Running test on docker machine with ubuntu image.
  • We are also using autoWorkerFixture to store session.

Expected

Trace should retain on test failures.

Actual

  • Trace is not being retained on test failure in before/after hooks.
@yury-s
Copy link
Member

yury-s commented Dec 20, 2023

Please share a reduced self-contained repro that we can run locally.

@surajsahu8
Copy link
Author

// -- Test file

import { test, expect } from './fixture';

test.describe('describe', () => {
test.afterAll(async ({ page }) => {
await expect(page.locator('<>').toContainText('example');
});

test('test', async ({<> }) => {
// Do something
});
});

@mmun
Copy link

mmun commented Dec 27, 2023

Probably related to #28348. See #28348 (comment) for a reproduction.

@cyrus-afshari
Copy link

@dgozman which playwright release has this fix? I'm on v1.43.1, and when I get a test timeout in a beforeAll hook, I don't get any screenshot, trace, or video in the Playwright Report. It produces 2 errors in the report instead:

Error: Target page, context or browser has been closed
Error: ENOENT: no such file or directory, open '<path>/playwright/test-results/.playwright-artifacts-0/4f4c1627c4601fe3c05e8ac7f793a5d6.zip'

Easily reproducible with a playwright.config that enables screenshots, trace, or video and the following beforeAll hook:
test.beforeAll('Intentionally cause a timeout in beforeAll', async ({ browser }) => { test.setTimeout(5000); const page = await browser.newPage(); await page.waitForTimeout(6000); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants