This commit is contained in:
Simon Knott 2025-02-06 12:53:12 +01:00
parent 9348dd4b6e
commit 0c70096473
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
7 changed files with 17 additions and 17 deletions

View file

@ -67,6 +67,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
options = { ...this._playwright._defaultLaunchOptions, ...options };
const launchOptions: channels.BrowserTypeLaunchParams = {
...options,
tracesDir: options.tracesDir ?? this._playwright._defaultTracesDir,
ignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined,
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
env: options.env ? envObjectToArray(options.env) : undefined,

View file

@ -65,7 +65,7 @@ export class APIRequest implements api.APIRequest {
options = {
...this._playwright._defaultContextOptions,
...options,
timeout: this._playwright._defaultActionTimeout ?? options.timeout,
timeout: this._playwright._defaultContextTimeout ?? options.timeout,
};
const storageState = typeof options.storageState === 'string' ?
JSON.parse(await fs.promises.readFile(options.storageState, 'utf8')) :
@ -74,12 +74,12 @@ export class APIRequest implements api.APIRequest {
...options,
extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,
storageState,
tracesDir: this._playwright._tracesDir,
tracesDir: this._playwright._defaultTracesDir,
clientCertificates: await toClientCertificatesProtocol(options.clientCertificates),
})).request);
this._contexts.add(context);
context._request = this;
context._tracing._tracesDir = this._playwright._tracesDir;
context._tracing._tracesDir = this._playwright._defaultTracesDir;
await context._instrumentation.runAfterCreateRequestContext(context);
return context;
}

View file

@ -42,8 +42,7 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
_defaultContextOptions?: BrowserContextOptions;
_defaultContextTimeout?: number;
_defaultContextNavigationTimeout?: number;
_defaultActionTimeout?: number;
_tracesDir?: string;
_defaultTracesDir?: string;
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PlaywrightInitializer) {
super(parent, type, guid, initializer);
@ -83,7 +82,7 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
return (channel as any)._object;
}
_browserTypes(): BrowserType[] {
private _browserTypes(): BrowserType[] {
return [this.chromium, this.firefox, this.webkit, this._bidiChromium, this._bidiFirefox];
}

View file

@ -83,11 +83,11 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
options.headless = headless;
if (channel !== undefined)
options.channel = channel;
options.tracesDir = tracing().tracesDir();
playwright._defaultTracesDir = tracing().tracesDir();
playwright._defaultLaunchOptions = options;
await use(options);
playwright._defaultLaunchOptions = undefined;
playwright._defaultTracesDir = undefined;
}, { scope: 'worker', auto: true, box: true }],
browser: [async ({ playwright, browserName, _browserOptions, connectOptions, _reuseContext }, use, testInfo) => {
@ -234,12 +234,12 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
playwright._defaultContextOptions = _combinedContextOptions;
playwright._defaultContextTimeout = actionTimeout || 0;
playwright._defaultContextNavigationTimeout = navigationTimeout || 0;
playwright._tracesDir = tracing().tracesDir();
playwright._defaultTracesDir = tracing().tracesDir();
await use();
playwright._defaultContextOptions = undefined;
playwright._defaultContextTimeout = undefined;
playwright._defaultContextNavigationTimeout = undefined;
playwright._tracesDir = undefined;
playwright._defaultTracesDir = undefined;
}, { auto: 'all-hooks-included', title: 'context configuration', box: true } as any],
_setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {

View file

@ -82,7 +82,7 @@ export class RemoteServer implements PlaywrightServer {
async _start(childProcess: CommonFixtures['childProcess'], browserType: BrowserType, channel: string, remoteServerOptions: RemoteServerOptions = {}) {
this._browserType = browserType;
const browserOptions = (browserType as any).plawright._defaultLaunchOptions;
const browserOptions = (browserType as any)._plawright._defaultLaunchOptions;
// Copy options to prevent a large JSON string when launching subprocess.
// Otherwise, we get `Error: spawn ENAMETOOLONG` on Windows.
const launchOptions: Parameters<BrowserType['launchServer']>[0] = {

View file

@ -630,14 +630,14 @@ for (const kind of ['launchServer', 'run-server'] as const) {
test('should filter launch options', async ({ connect, startRemoteServer, server, browserType }, testInfo) => {
const tracesDir = testInfo.outputPath('traces');
const oldTracesDir = (browserType as any)._playwright._defaultLaunchOptions.tracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = tracesDir;
const oldTracesDir = (browserType as any)._playwright._defaultTracesDir;
(browserType as any)._playwright._defaultTracesDir = tracesDir;
const remoteServer = await startRemoteServer(kind);
const browser = await connect(remoteServer.wsEndpoint());
const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE);
await browser.close();
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = oldTracesDir;
(browserType as any)._playwright._defaultTracesDir = oldTracesDir;
expect(fs.existsSync(tracesDir)).toBe(false);
});

View file

@ -368,8 +368,8 @@ test('should not crash when browser closes mid-trace', async ({ browserType, ser
});
test('should survive browser.close with auto-created traces dir', async ({ browserType }, testInfo) => {
const oldTracesDir = (browserType as any)._playwright._defaultLaunchOptions.tracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = undefined;
const oldTracesDir = (browserType as any)._playwright._defaultTracesDir;
(browserType as any)._playwright._defaultTracesDir = undefined;
const browser = await browserType.launch();
const page = await browser.newPage();
await page.context().tracing.start();
@ -394,7 +394,7 @@ test('should survive browser.close with auto-created traces dir', async ({ brows
]);
done.value = true;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = oldTracesDir;
(browserType as any)._playwright._defaultTracesDir = oldTracesDir;
});
test('should not stall on dialogs', async ({ page, context, server }) => {