playwright: [BUG] Electron launch `recordVideo` causes timeout only on windows

System info

  • Playwright Version: 1.36.2
  • Operating System: Windows
  • Browser: All

Source code

  • [ x] I provided exact source code that allows reproducing the issue locally.

This test will not run on Windows

import {
  test,
  expect,
  _electron as electron,
  Page,
  ElectronApplication,
} from '@playwright/test';
import path from 'path';

test.describe('Uptime Reporting', () => {
  let page: Page;
  let electronApp: ElectronApplication;

  test.beforeAll(async () => {
    electronApp = await electron.launch({
      args: [
        path.join(__dirname, '..', 'release', 'app', 'dist', 'main', 'main.js'),
      ],

      recordVideo: {
        dir: path.join(__dirname, '..', 'playwright-videos'),
        size: {
          width: 1280,
          height: 720,
        },
      },
    });

    page = await electronApp.firstWindow();

    await page.reload();

    page.on('console', console.log);
  });

  test.afterAll(async () => {
    await electronApp.close();
  });
});

Config file

// eslint-disable-next-line
import { defineConfig } from '@playwright/test';

import dotenv from 'dotenv';

dotenv.config();

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir: './tests',
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* 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,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [['json', { outputFile: 'test-results/results.json' }], ['html']],

  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    // THIS does not work on eletron, as we do not have a projects array
    baseURL: 'http://127.0.0.1:1212',

    video: 'on',

    contextOptions: {
      // this is just not working for us idk why
      recordVideo: {
        dir: 'playwright-videos',
      },
    },

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */

    trace: 'on-first-retry',
  },

  /* Configure projects for major browsers */

  /* Run your local dev server before starting the tests */
  webServer:
    process.env.NODE_ENV === 'development'
      ? {
          command: 'npm run start:playwright',
          url: 'http://127.0.0.1:1212',
          reuseExistingServer: false,
        }
      : undefined,
});

Steps

  • Run the test from above

Expected It should not hang

[Describe expected behavior]

Actual It hangs

Workaround

If you remove the recordVideo option this test runs perfectly fine on Windows, so there is an issue with this option. There is no issue on linux or mac with the record video option

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

npx playwright install chromium fixed the issue for me.

@yury-s this is the same thing I reported in https://github.com/microsoft/playwright/issues/20575#issuecomment-1761901376

Here are the steps to reproduce (tested against "@playwright/test": "1.39.0")

import { test } from '@playwright/test'

const findExecutablePath = () => {
 // path to your executable
 return "MyElectronApp.app/Contents/MacOS/MyElectronApp"
}

test.describe('Record Video bug', () => {
  test('Works when recordVideo is not set', async ({ playwright }) => {
    const electronApp = await playwright._electron.launch({
      executablePath: findExecutablePath(),
    })

    console.log('Before firstWindow()', electronApp.windows().length)
    await electronApp.firstWindow()
    console.log('After firstWindow()', electronApp.windows().length)
  })

  test('Hangs when recordVideo is set', async ({ playwright }) => {
    const electronApp = await playwright._electron.launch({
      executablePath: findExecutablePath(),
      recordVideo: {
        dir: 'test-results/videos',
      },
    })

    console.log('Before firstWindow()', electronApp.windows().length)
    await electronApp.firstWindow()
    console.log('After firstWindow()', electronApp.windows().length)
  })
})

Output:

Running 2 tests using 1 worker

  ✓  1 [chromium] › specs/repro-record-video.spec.ts:24:7 › Record Video bug › Works when recordVideo is not set (5.4s)
Before firstWindow() 1
After firstWindow() 1
  ✘  2 [chromium] › specs/repro-record-video.spec.ts:34:7 › Record Video bug › Hangs when recordVideo is set (4.5s)
Before firstWindow() 0


  1) [chromium] › specs/repro-record-video.spec.ts:34:7 › Record Video bug › Hangs when recordVideo is set 

    Error: electronApplication.firstWindow: Electron application closed

      41 |
      42 |     console.log('Before firstWindow()', electronApp.windows().length)
    > 43 |     await electronApp.firstWindow()
         |                       ^
      44 |     console.log('After firstWindow()', electronApp.windows().length)
      45 |   })
      46 | })

Could you kindly re-open this issue? 🙏

@yury-s i will attempt to get a reproduction repo for you when I get a chance