1515 */
1616import { test } from './npmTest' ;
1717import fs from 'fs' ;
18+ import { expect } from 'packages/playwright-test' ;
1819import path from 'path' ;
1920
2021test ( 'electron should work' , async ( { exec, tsc, writeFiles } ) => {
@@ -39,3 +40,46 @@ test('electron should work with special characters in path', async ({ exec, tmpW
3940 cwd : path . join ( folderName )
4041 } ) ;
4142} ) ;
43+
44+ test ( 'should work when wrapped inside @playwright/test and trace is enabled' , async ( { exec, tmpWorkspace, writeFiles } ) => {
45+ await exec ( 'npm i -D @playwright/test electron@31' ) ;
46+ await writeFiles ( {
47+ 'electron-with-tracing.spec.ts' : `
48+ import { test, expect, _electron } from '@playwright/test';
49+
50+ test('should work', async ({ trace }) => {
51+ const electronApp = await _electron.launch({ args: [${ JSON . stringify ( path . join ( __dirname , '../electron/electron-window-app.js' ) ) } ] });
52+
53+ const window = await electronApp.firstWindow();
54+ if (trace)
55+ await window.context().tracing.start({ screenshots: true, snapshots: true });
56+
57+ await window.goto('data:text/html,<title>Playwright</title><h1>Playwright</h1>');
58+ await expect(window).toHaveTitle(/Playwright/);
59+ await expect(window.getByRole('heading')).toHaveText('Playwright');
60+
61+ const path = test.info().outputPath('electron-trace.zip');
62+ if (trace) {
63+ await window.context().tracing.stop({ path });
64+ test.info().attachments.push({ name: 'trace', path, contentType: 'application/zip' });
65+ }
66+ await electronApp.close();
67+ });
68+ ` ,
69+ } ) ;
70+ const jsonOutputName = test . info ( ) . outputPath ( 'report.json' ) ;
71+ await exec ( 'npx playwright test --trace=on --reporter=json electron-with-tracing.spec.ts' , {
72+ env : { PLAYWRIGHT_JSON_OUTPUT_NAME : jsonOutputName }
73+ } ) ;
74+ const traces = [
75+ // our actual trace.
76+ path . join ( tmpWorkspace , 'test-results' , 'electron-with-tracing-should-work' , 'electron-trace.zip' ) ,
77+ // contains the expect() calls
78+ path . join ( tmpWorkspace , 'test-results' , 'electron-with-tracing-should-work' , 'trace.zip' ) ,
79+ ] ;
80+ for ( const trace of traces )
81+ expect ( fs . existsSync ( trace ) ) . toBe ( true ) ;
82+ const report = JSON . parse ( fs . readFileSync ( jsonOutputName , 'utf-8' ) ) ;
83+ expect ( new Set ( [ 'trace' ] ) ) . toEqual ( new Set ( report . suites [ 0 ] . specs [ 0 ] . tests [ 0 ] . results [ 0 ] . attachments . map ( a => a . name ) ) ) ;
84+ expect ( new Set ( traces . map ( p => fs . realpathSync ( p ) ) ) ) . toEqual ( new Set ( report . suites [ 0 ] . specs [ 0 ] . tests [ 0 ] . results [ 0 ] . attachments . map ( a => a . path ) ) ) ;
85+ } ) ;
0 commit comments