Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(electron): extend args test (#21388)
Pavel Feldman7f8db8f3c051
diff --git a/tests/electron/electron-app-args.js b/tests/electron/electron-app-args.jsnew file mode 100644index 0000000000..b7b8407a4f--- /dev/null+++ b/tests/electron/electron-app-args.js@@ -0,0 +1 @@+globalThis.argv = process.argv.slice(0);diff --git a/tests/electron/electron-app.spec.ts b/tests/electron/electron-app.spec.tsindex 5c43b67cf0..14771819f8 100644--- a/tests/electron/electron-app.spec.ts+++ b/tests/electron/electron-app.spec.ts@@ -48,9 +48,10 @@ test('should script application', async ({ electronApp }) => {expect(appPath).toBe(path.resolve(__dirname));});-test('should preserve args', async ({ electronApp }) => {- const argv = await electronApp.evaluate(async () => process.argv);- expect(argv.slice(1)).toEqual([expect.stringContaining(path.join('electron', 'electron-app.js'))]);+test('should preserve args', async ({ launchElectronApp }) => {+ const electronApp = await launchElectronApp('electron-app-args.js', ['foo', 'bar']);+ const argv = await electronApp.evaluate(async () => globalThis.argv);+ expect(argv).toEqual([expect.stringContaining(path.join('dist', 'electron')), expect.stringContaining(path.join('electron', 'electron-app-args.js')), 'foo', 'bar']);});test('should return windows', async ({ electronApp, newWindow }) => {@@ -118,7 +119,7 @@ test('should return browser window', async ({ launchElectronApp }) => {});test('should bypass csp', async ({ launchElectronApp, server }) => {- const app = await launchElectronApp('electron-app.js', { bypassCSP: true });+ const app = await launchElectronApp('electron-app.js', [], { bypassCSP: true });await app.evaluate(electron => {const window = new electron.BrowserWindow({width: 800,@@ -167,7 +168,7 @@ test('should return same browser window for browser view pages', async ({ launch});test('should record video', async ({ launchElectronApp }, testInfo) => {- const app = await launchElectronApp('electron-window-app.js', {+ const app = await launchElectronApp('electron-window-app.js', [], {recordVideo: { dir: testInfo.outputPath('video') }});const page = await app.firstWindow();diff --git a/tests/electron/electronTest.ts b/tests/electron/electronTest.tsindex 881e245b99..05361a20ff 100644--- a/tests/electron/electronTest.ts+++ b/tests/electron/electronTest.ts@@ -26,7 +26,7 @@ import { assert } from '../../packages/playwright-core/lib/utils/debug';type ElectronTestFixtures = PageTestFixtures & {electronApp: ElectronApplication;- launchElectronApp: (appFile: string, options?: any) => Promise<ElectronApplication>;+ launchElectronApp: (appFile: string, args?: string[], options?: any) => Promise<ElectronApplication>;newWindow: () => Promise<Page>;};@@ -45,8 +45,8 @@ export const electronTest = baseTest.extend<TraceViewerFixtures>(traceViewerFixt// This env prevents 'Electron Security Policy' console message.process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';const apps: ElectronApplication[] = [];- await use(async (appFile: string, options?: any[]) => {- const app = await playwright._electron.launch({ ...options, args: [path.join(__dirname, appFile)] });+ await use(async (appFile: string, args: string[] = [], options?: any[]) => {+ const app = await playwright._electron.launch({ ...options, args: [path.join(__dirname, appFile), ...args] });apps.push(app);return app;});