feat(electron): support tracesDir option (#23947)

References #23620.
This commit is contained in:
Dmitry Gozman 2023-06-28 16:32:16 -07:00 committed by GitHub
parent b0b429fed0
commit 1ab99fe1b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 2 deletions

View File

@ -142,3 +142,6 @@ Maximum time in milliseconds to wait for the application to start. Defaults to `
### option: Electron.launch.timezoneId = %%-context-option-timezoneid-%%
* since: v1.12
### option: Electron.launch.tracesDir = %%-browser-option-tracesdir-%%
* since: v1.36

View File

@ -51,6 +51,7 @@ export class Electron extends ChannelOwner<channels.ElectronChannel> implements
const params: channels.ElectronLaunchParams = {
...await prepareBrowserContextParams(options),
env: envObjectToArray(options.env ? options.env : process.env),
tracesDir: options.tracesDir,
};
const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
app._context._options = params;

View File

@ -2240,6 +2240,7 @@ scheme.ElectronLaunchParams = tObject({
})),
strictSelectors: tOptional(tBoolean),
timezoneId: tOptional(tString),
tracesDir: tOptional(tString),
});
scheme.ElectronLaunchResult = tObject({
electronApplication: tChannel(['ElectronApplication']),

View File

@ -231,7 +231,7 @@ export class Electron extends SdkObject {
browserLogsCollector,
artifactsDir,
downloadsPath: artifactsDir,
tracesDir: artifactsDir,
tracesDir: options.tracesDir || artifactsDir,
originalLaunchOptions: {},
};
validateBrowserContextOptions(contextOptions, browserOptions);

View File

@ -16995,6 +16995,11 @@ export interface Electron {
* for a list of supported timezone IDs. Defaults to the system timezone.
*/
timezoneId?: string;
/**
* If specified, traces are saved into this directory.
*/
tracesDir?: string;
}): Promise<ElectronApplication>;
}

View File

@ -4015,6 +4015,7 @@ export type ElectronLaunchParams = {
},
strictSelectors?: boolean,
timezoneId?: string,
tracesDir?: string,
};
export type ElectronLaunchOptions = {
executablePath?: string,
@ -4049,6 +4050,7 @@ export type ElectronLaunchOptions = {
},
strictSelectors?: boolean,
timezoneId?: string,
tracesDir?: string,
};
export type ElectronLaunchResult = {
electronApplication: ElectronApplicationChannel,

View File

@ -3176,6 +3176,7 @@ Electron:
height: number
strictSelectors: boolean?
timezoneId: string?
tracesDir: string?
returns:
electronApplication: ElectronApplication

View File

@ -15,9 +15,10 @@
*/
import { electronTest as test, expect } from './electronTest';
import fs from 'fs';
import path from 'path';
test.skip(({ trace }) => trace === 'on');
// test.slow();
test('should record trace', async ({ newWindow, server, runAndTrace }) => {
const traceViewer = await runAndTrace(async () => {
@ -45,3 +46,17 @@ test('should support custom protocol', async ({ electronApp, newWindow, server,
await expect(frame.locator('button')).toHaveCSS('color', 'rgb(255, 0, 0)');
await expect(frame.locator('button')).toHaveCSS('font-weight', '700');
});
test('should respect tracesDir and name', async ({ launchElectronApp, server }, testInfo) => {
const tracesDir = testInfo.outputPath('traces');
const electronApp = await launchElectronApp('electron-window-app.js', [], { tracesDir });
await electronApp.context().tracing.start({ name: 'name1', snapshots: true });
const page = await electronApp.firstWindow();
await page.goto(server.PREFIX + '/one-style.html');
await electronApp.context().tracing.stopChunk({ path: testInfo.outputPath('trace1.zip') });
expect(fs.existsSync(path.join(tracesDir, 'name1.trace'))).toBe(true);
expect(fs.existsSync(path.join(tracesDir, 'name1.network'))).toBe(true);
await electronApp.close();
});