(browserType as any)

This commit is contained in:
Simon Knott 2025-02-06 10:49:36 +01:00
parent 8a22302e43
commit a8795ce67f
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
8 changed files with 17 additions and 17 deletions

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)._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

@ -20,7 +20,7 @@ import type { BrowserContext, Page } from '@playwright/test';
const test = browserTest.extend<{ reusedContext: () => Promise<BrowserContext> }>({
reusedContext: async ({ browserType, browser }, use) => {
await use(async () => {
const defaultContextOptions = (browserType as any)._defaultContextOptions;
const defaultContextOptions = (browserType as any)._playwright._defaultContextOptions;
const context = await (browser as any)._newContextForReuse(defaultContextOptions);
return context;
});

View file

@ -21,7 +21,7 @@ import { playwrightTest as test, expect } from '../config/browserTest';
test('browserType.executablePath should work', async ({ browserType, channel, mode }) => {
test.skip(!!channel, 'We skip browser download when testing a channel');
test.skip(mode.startsWith('service'));
test.skip(!!(browserType as any)._defaultLaunchOptions.executablePath, 'Skip with custom executable path');
test.skip(!!(browserType as any)._playwright._defaultLaunchOptions.executablePath, 'Skip with custom executable path');
const executablePath = browserType.executablePath();
expect(fs.existsSync(executablePath)).toBe(true);

View file

@ -40,7 +40,7 @@ const test = playwrightTest.extend<ExtraFixtures>({
await use(async (wsEndpoint, options = {}, redirectPortForTest): Promise<Browser> => {
(options as any).__testHookRedirectPortForwarding = redirectPortForTest;
options.headers = {
'x-playwright-launch-options': JSON.stringify((browserType as any)._defaultLaunchOptions || {}),
'x-playwright-launch-options': JSON.stringify((browserType as any)._playwright._defaultLaunchOptions || {}),
...options.headers,
};
browser = await browserType.connect(wsEndpoint, options);
@ -173,8 +173,8 @@ for (const kind of ['launchServer', 'run-server'] as const) {
test('should ignore page.pause when headed', async ({ connect, startRemoteServer, browserType, channel }) => {
test.skip(channel === 'chromium-headless-shell', 'shell is never headed');
const headless = (browserType as any)._defaultLaunchOptions.headless;
(browserType as any)._defaultLaunchOptions.headless = false;
const headless = (browserType as any)._playwright._defaultLaunchOptions.headless;
(browserType as any)._playwright._defaultLaunchOptions.headless = false;
const remoteServer = await startRemoteServer(kind);
const browser = await connect(remoteServer.wsEndpoint());
const browserContext = await browser.newContext();
@ -182,7 +182,7 @@ for (const kind of ['launchServer', 'run-server'] as const) {
// @ts-ignore
await page.pause({ __testHookKeepTestTimeout: true });
await browser.close();
(browserType as any)._defaultLaunchOptions.headless = headless;
(browserType as any)._playwright._defaultLaunchOptions.headless = headless;
});
test('should be able to visit ipv6 through localhost', async ({ connect, startRemoteServer, ipV6ServerPort }) => {
@ -599,7 +599,7 @@ for (const kind of ['launchServer', 'run-server'] as const) {
const browser = await browserType.connect({
wsEndpoint: remoteServer.wsEndpoint(),
headers: {
'x-playwright-launch-options': JSON.stringify((browserType as any)._defaultLaunchOptions || {}),
'x-playwright-launch-options': JSON.stringify((browserType as any)._playwright._defaultLaunchOptions || {}),
},
});
const page = await browser.newPage();
@ -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)._defaultLaunchOptions.tracesDir;
(browserType as any)._defaultLaunchOptions.tracesDir = tracesDir;
const oldTracesDir = (browserType as any)._playwright._defaultLaunchOptions.tracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = 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)._defaultLaunchOptions.tracesDir = oldTracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = oldTracesDir;
expect(fs.existsSync(tracesDir)).toBe(false);
});

View file

@ -51,7 +51,7 @@ const test = baseTest.extend<Fixtures>({
await use(async () => {
const browser = await browserType.connect(wsEndpoint, {
headers: {
'x-playwright-launch-options': JSON.stringify((browserType as any)._defaultLaunchOptions),
'x-playwright-launch-options': JSON.stringify((browserType as any)._playwright._defaultLaunchOptions),
'x-playwright-reuse-context': '1',
},
}) as BrowserWithReuse;

View file

@ -150,7 +150,7 @@ it('should have passed URL when launching with ignoreDefaultArgs: true', async (
it.skip(mode !== 'default');
const userDataDir = await createUserDataDir();
const args = toImpl(browserType).defaultArgs((browserType as any)._defaultLaunchOptions, 'persistent', userDataDir, 0).filter(a => a !== 'about:blank');
const args = toImpl(browserType).defaultArgs((browserType as any)._playwright._defaultLaunchOptions, 'persistent', userDataDir, 0).filter(a => a !== 'about:blank');
const options = {
args: browserName === 'firefox' ? [...args, '-new-tab', server.EMPTY_PAGE] : [...args, server.EMPTY_PAGE],
ignoreDefaultArgs: true,

View file

@ -255,7 +255,7 @@ it('should set playwright as user-agent', async ({ playwright, server, isWindows
});
it('should be able to construct with context options', async ({ playwright, browserType, server }) => {
const request = await playwright.request.newContext((browserType as any)._defaultContextOptions);
const request = await playwright.request.newContext((browserType as any)._playwright._defaultContextOptions);
const response = await request.get(server.EMPTY_PAGE);
expect(response.ok()).toBeTruthy();
await request.dispose();

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)._defaultLaunchOptions.tracesDir;
(browserType as any)._defaultLaunchOptions.tracesDir = undefined;
const oldTracesDir = (browserType as any)._playwright._defaultLaunchOptions.tracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = 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)._defaultLaunchOptions.tracesDir = oldTracesDir;
(browserType as any)._playwright._defaultLaunchOptions.tracesDir = oldTracesDir;
});
test('should not stall on dialogs', async ({ page, context, server }) => {