Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import { stepTitle } from './util';
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, ScreenshotMode, TestInfo, TestType, VideoMode } from '../types/test';
import type { ContextReuseMode } from './common/config';
import type { TestInfoImpl, TestStepInternal } from './worker/testInfo';
import type { ClientInstrumentation, ClientInstrumentationListener } from '../../playwright-core/src/client/clientInstrumentation';
import type { ClientInstrumentationListener } from '../../playwright-core/src/client/clientInstrumentation';
import type { Playwright as PlaywrightImpl } from '../../playwright-core/src/client/playwright';
import type { Browser as BrowserImpl } from '../../playwright-core/src/client/browser';
import type { BrowserContext as BrowserContextImpl } from '../../playwright-core/src/client/browserContext';
import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, LaunchOptions, Page, Tracing, Video } from 'playwright-core';

export { expect } from './matchers/expect';
Expand Down Expand Up @@ -110,15 +112,15 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
},
});
await use(browser);
await (browser as any)._wrapApiCall(async () => {
await (browser as BrowserImpl)._wrapApiCall(async () => {
await browser.close({ reason: 'Test ended.' });
}, { internal: true });
return;
}

const browser = await playwright[browserName].launch();
await use(browser);
await (browser as any)._wrapApiCall(async () => {
await (browser as BrowserImpl)._wrapApiCall(async () => {
await browser.close({ reason: 'Test ended.' });
}, { internal: true });
}, { scope: 'worker', timeout: 0 }],
Expand Down Expand Up @@ -318,7 +320,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
},
};

const clientInstrumentation = (playwright as any)._instrumentation as ClientInstrumentation;
const clientInstrumentation = (playwright as PlaywrightImpl)._instrumentation;
clientInstrumentation.addListener(csiListener);

await use();
Expand Down Expand Up @@ -355,12 +357,12 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
context.on('page', page => contextData.pagesWithVideo.push(page));

if (process.env.PW_CLOCK === 'frozen') {
await (context as any)._wrapApiCall(async () => {
await (context as BrowserContextImpl)._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
await context.clock.pauseAt(1000);
}, { internal: true });
} else if (process.env.PW_CLOCK === 'realtime') {
await (context as any)._wrapApiCall(async () => {
await (context as BrowserContextImpl)._wrapApiCall(async () => {
await context.clock.install({ time: 0 });
}, { internal: true });
}
Expand All @@ -371,7 +373,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
let counter = 0;
const closeReason = testInfo.status === 'timedOut' ? 'Test timeout of ' + testInfo.timeout + 'ms exceeded.' : 'Test ended.';
await Promise.all([...contexts.keys()].map(async context => {
await (context as any)._wrapApiCall(async () => {
await (context as BrowserContextImpl)._wrapApiCall(async () => {
await context.close({ reason: closeReason });
}, { internal: true });
const testFailed = testInfo.status !== testInfo.expectedStatus;
Expand Down Expand Up @@ -413,10 +415,10 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
}

const defaultContextOptions = (playwright.chromium as any)._defaultContextOptions as BrowserContextOptions;
const context = await (browser as any)._newContextForReuse(defaultContextOptions);
const context = await (browser as BrowserImpl)._newContextForReuse(defaultContextOptions);
await use(context);
const closeReason = testInfo.status === 'timedOut' ? 'Test timeout of ' + testInfo.timeout + 'ms exceeded.' : 'Test ended.';
await (browser as any)._disconnectFromReusedContext(closeReason);
await (browser as BrowserImpl)._disconnectFromReusedContext(closeReason);
},

page: async ({ context, _reuseContext }, use) => {
Expand Down Expand Up @@ -471,7 +473,7 @@ function normalizeScreenshotMode(screenshot: ScreenshotOption): ScreenshotMode {
}

function attachConnectedHeaderIfNeeded(testInfo: TestInfo, browser: Browser | null) {
const connectHeaders: { name: string, value: string }[] | undefined = (browser as any)?._connection.headers;
const connectHeaders: { name: string, value: string }[] | undefined = (browser as BrowserImpl | null)?._connection.headers;
if (!connectHeaders)
return;
for (const header of connectHeaders) {
Expand Down
Loading