move some more
This commit is contained in:
parent
0dea2f44b0
commit
8a22302e43
|
|
@ -80,7 +80,7 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
|
||||||
}
|
}
|
||||||
|
|
||||||
async _innerNewContext(options: BrowserContextOptions = {}, forReuse: boolean): Promise<BrowserContext> {
|
async _innerNewContext(options: BrowserContextOptions = {}, forReuse: boolean): Promise<BrowserContext> {
|
||||||
options = { ...this._browserType._defaultContextOptions, ...options };
|
options = { ...this._browserType._playwright._defaultContextOptions, ...options };
|
||||||
const contextOptions = await prepareBrowserContextParams(options);
|
const contextOptions = await prepareBrowserContextParams(options);
|
||||||
const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
|
const response = forReuse ? await this._channel.newContextForReuse(contextOptions) : await this._channel.newContext(contextOptions);
|
||||||
const context = BrowserContext.from(response.context);
|
const context = BrowserContext.from(response.context);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import type * as channels from '@protocol/channels';
|
||||||
import { Browser } from './browser';
|
import { Browser } from './browser';
|
||||||
import { BrowserContext, prepareBrowserContextParams } from './browserContext';
|
import { BrowserContext, prepareBrowserContextParams } from './browserContext';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
import type { LaunchOptions, LaunchServerOptions, ConnectOptions, LaunchPersistentContextOptions, BrowserContextOptions, Logger } from './types';
|
import type { LaunchOptions, LaunchServerOptions, ConnectOptions, LaunchPersistentContextOptions, Logger } from './types';
|
||||||
import { Connection } from './connection';
|
import { Connection } from './connection';
|
||||||
import { Events } from './events';
|
import { Events } from './events';
|
||||||
import type { ChildProcess } from 'child_process';
|
import type { ChildProcess } from 'child_process';
|
||||||
|
|
@ -45,11 +45,6 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
_contexts = new Set<BrowserContext>();
|
_contexts = new Set<BrowserContext>();
|
||||||
_playwright!: Playwright;
|
_playwright!: Playwright;
|
||||||
|
|
||||||
// Instrumentation.
|
|
||||||
_defaultContextOptions?: BrowserContextOptions;
|
|
||||||
_defaultContextTimeout?: number;
|
|
||||||
_defaultContextNavigationTimeout?: number;
|
|
||||||
|
|
||||||
static from(browserType: channels.BrowserTypeChannel): BrowserType {
|
static from(browserType: channels.BrowserTypeChannel): BrowserType {
|
||||||
return (browserType as any)._object;
|
return (browserType as any)._object;
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +88,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
|
async launchPersistentContext(userDataDir: string, options: LaunchPersistentContextOptions = {}): Promise<BrowserContext> {
|
||||||
const logger = options.logger || this._playwright._defaultLaunchOptions?.logger;
|
const logger = options.logger || this._playwright._defaultLaunchOptions?.logger;
|
||||||
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
assert(!(options as any).port, 'Cannot specify a port without launching as a server.');
|
||||||
options = { ...this._playwright._defaultLaunchOptions, ...this._defaultContextOptions, ...options };
|
options = { ...this._playwright._defaultLaunchOptions, ...this._playwright._defaultContextOptions, ...options };
|
||||||
const contextParams = await prepareBrowserContextParams(options);
|
const contextParams = await prepareBrowserContextParams(options);
|
||||||
const persistentParams: channels.BrowserTypeLaunchPersistentContextParams = {
|
const persistentParams: channels.BrowserTypeLaunchPersistentContextParams = {
|
||||||
...contextParams,
|
...contextParams,
|
||||||
|
|
@ -236,10 +231,10 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
|
||||||
context._browserType = this;
|
context._browserType = this;
|
||||||
this._contexts.add(context);
|
this._contexts.add(context);
|
||||||
context._setOptions(contextOptions, browserOptions);
|
context._setOptions(contextOptions, browserOptions);
|
||||||
if (this._defaultContextTimeout !== undefined)
|
if (this._playwright._defaultContextTimeout !== undefined)
|
||||||
context.setDefaultTimeout(this._defaultContextTimeout);
|
context.setDefaultTimeout(this._playwright._defaultContextTimeout);
|
||||||
if (this._defaultContextNavigationTimeout !== undefined)
|
if (this._playwright._defaultContextNavigationTimeout !== undefined)
|
||||||
context.setDefaultNavigationTimeout(this._defaultContextNavigationTimeout);
|
context.setDefaultNavigationTimeout(this._playwright._defaultContextNavigationTimeout);
|
||||||
await this._instrumentation.runAfterCreateBrowserContext(context);
|
await this._instrumentation.runAfterCreateBrowserContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,30 +57,29 @@ export class APIRequest implements api.APIRequest {
|
||||||
private _playwright: Playwright;
|
private _playwright: Playwright;
|
||||||
readonly _contexts = new Set<APIRequestContext>();
|
readonly _contexts = new Set<APIRequestContext>();
|
||||||
|
|
||||||
// Instrumentation.
|
|
||||||
_defaultContextOptions?: NewContextOptions & { tracesDir?: string };
|
|
||||||
|
|
||||||
constructor(playwright: Playwright) {
|
constructor(playwright: Playwright) {
|
||||||
this._playwright = playwright;
|
this._playwright = playwright;
|
||||||
}
|
}
|
||||||
|
|
||||||
async newContext(options: NewContextOptions = {}): Promise<APIRequestContext> {
|
async newContext(options: NewContextOptions = {}): Promise<APIRequestContext> {
|
||||||
options = { ...this._defaultContextOptions, ...options };
|
options = {
|
||||||
|
...this._playwright._defaultContextOptions,
|
||||||
|
...options,
|
||||||
|
timeout: this._playwright._defaultActionTimeout ?? options.timeout,
|
||||||
|
};
|
||||||
const storageState = typeof options.storageState === 'string' ?
|
const storageState = typeof options.storageState === 'string' ?
|
||||||
JSON.parse(await fs.promises.readFile(options.storageState, 'utf8')) :
|
JSON.parse(await fs.promises.readFile(options.storageState, 'utf8')) :
|
||||||
options.storageState;
|
options.storageState;
|
||||||
// We do not expose tracesDir in the API, so do not allow options to accidentally override it.
|
|
||||||
const tracesDir = this._defaultContextOptions?.tracesDir;
|
|
||||||
const context = APIRequestContext.from((await this._playwright._channel.newRequest({
|
const context = APIRequestContext.from((await this._playwright._channel.newRequest({
|
||||||
...options,
|
...options,
|
||||||
extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,
|
extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,
|
||||||
storageState,
|
storageState,
|
||||||
tracesDir,
|
tracesDir: this._playwright._tracesDir,
|
||||||
clientCertificates: await toClientCertificatesProtocol(options.clientCertificates),
|
clientCertificates: await toClientCertificatesProtocol(options.clientCertificates),
|
||||||
})).request);
|
})).request);
|
||||||
this._contexts.add(context);
|
this._contexts.add(context);
|
||||||
context._request = this;
|
context._request = this;
|
||||||
context._tracing._tracesDir = tracesDir;
|
context._tracing._tracesDir = this._playwright._tracesDir;
|
||||||
await context._instrumentation.runAfterCreateRequestContext(context);
|
await context._instrumentation.runAfterCreateRequestContext(context);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import { ChannelOwner } from './channelOwner';
|
||||||
import { Electron } from './electron';
|
import { Electron } from './electron';
|
||||||
import { APIRequest } from './fetch';
|
import { APIRequest } from './fetch';
|
||||||
import { Selectors, SelectorsOwner } from './selectors';
|
import { Selectors, SelectorsOwner } from './selectors';
|
||||||
import type { LaunchOptions } from './types';
|
import type { BrowserContextOptions, LaunchOptions } from 'playwright-core';
|
||||||
|
|
||||||
export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
|
export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
|
||||||
readonly _android: Android;
|
readonly _android: Android;
|
||||||
|
|
@ -37,7 +37,13 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
|
||||||
readonly request: APIRequest;
|
readonly request: APIRequest;
|
||||||
readonly errors: { TimeoutError: typeof TimeoutError };
|
readonly errors: { TimeoutError: typeof TimeoutError };
|
||||||
|
|
||||||
|
// Instrumentation.
|
||||||
_defaultLaunchOptions?: LaunchOptions;
|
_defaultLaunchOptions?: LaunchOptions;
|
||||||
|
_defaultContextOptions?: BrowserContextOptions;
|
||||||
|
_defaultContextTimeout?: number;
|
||||||
|
_defaultContextNavigationTimeout?: number;
|
||||||
|
_defaultActionTimeout?: number;
|
||||||
|
_tracesDir?: string;
|
||||||
|
|
||||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PlaywrightInitializer) {
|
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.PlaywrightInitializer) {
|
||||||
super(parent, type, guid, initializer);
|
super(parent, type, guid, initializer);
|
||||||
|
|
|
||||||
|
|
@ -231,21 +231,15 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
||||||
if (debugMode())
|
if (debugMode())
|
||||||
(testInfo as TestInfoImpl)._setDebugMode();
|
(testInfo as TestInfoImpl)._setDebugMode();
|
||||||
|
|
||||||
for (const browserType of playwright._browserTypes()) {
|
playwright._defaultContextOptions = _combinedContextOptions;
|
||||||
browserType._defaultContextOptions = _combinedContextOptions;
|
playwright._defaultContextTimeout = actionTimeout || 0;
|
||||||
browserType._defaultContextTimeout = actionTimeout || 0;
|
playwright._defaultContextNavigationTimeout = navigationTimeout || 0;
|
||||||
browserType._defaultContextNavigationTimeout = navigationTimeout || 0;
|
playwright._tracesDir = tracing().tracesDir();
|
||||||
}
|
|
||||||
playwright.request._defaultContextOptions = { ..._combinedContextOptions };
|
|
||||||
playwright.request._defaultContextOptions.tracesDir = tracing().tracesDir();
|
|
||||||
playwright.request._defaultContextOptions.timeout = actionTimeout || 0;
|
|
||||||
await use();
|
await use();
|
||||||
playwright.request._defaultContextOptions = undefined;
|
playwright._defaultContextOptions = undefined;
|
||||||
for (const browserType of playwright._browserTypes()) {
|
playwright._defaultContextTimeout = undefined;
|
||||||
browserType._defaultContextOptions = undefined;
|
playwright._defaultContextNavigationTimeout = undefined;
|
||||||
browserType._defaultContextTimeout = undefined;
|
playwright._tracesDir = undefined;
|
||||||
browserType._defaultContextNavigationTimeout = undefined;
|
|
||||||
}
|
|
||||||
}, { auto: 'all-hooks-included', title: 'context configuration', box: true } as any],
|
}, { auto: 'all-hooks-included', title: 'context configuration', box: true } as any],
|
||||||
|
|
||||||
_setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {
|
_setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue