chore(default context): Apply context workaround only when browser and scenario match (#15904)
This commit is contained in:
parent
a94fe361a2
commit
68d558f896
|
|
@ -295,7 +295,8 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
|
|
||||||
async _loadDefaultContext(progress: Progress) {
|
async _loadDefaultContext(progress: Progress) {
|
||||||
const pages = await this._loadDefaultContextAsIs(progress);
|
const pages = await this._loadDefaultContextAsIs(progress);
|
||||||
if (this._options.isMobile || this._options.locale) {
|
const browserName = this._browser.options.name;
|
||||||
|
if ((this._options.isMobile && browserName === 'chromium') || (this._options.locale && browserName === 'webkit')) {
|
||||||
// Workaround for:
|
// Workaround for:
|
||||||
// - chromium fails to change isMobile for existing page;
|
// - chromium fails to change isMobile for existing page;
|
||||||
// - webkit fails to change locale for existing page.
|
// - webkit fails to change locale for existing page.
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ it('should have pages', async ({ contextFactory, server }, testInfo) => {
|
||||||
expect(pageEntry.pageTimings.onLoad).toBeGreaterThan(0);
|
expect(pageEntry.pageTimings.onLoad).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have pages in persistent context', async ({ launchPersistent }, testInfo) => {
|
it('should have pages in persistent context', async ({ launchPersistent, browserName }, testInfo) => {
|
||||||
const harPath = testInfo.outputPath('test.har');
|
const harPath = testInfo.outputPath('test.har');
|
||||||
const { context, page } = await launchPersistent({ recordHar: { path: harPath } });
|
const { context, page } = await launchPersistent({ recordHar: { path: harPath } });
|
||||||
await page.goto('data:text/html,<title>Hello</title>');
|
await page.goto('data:text/html,<title>Hello</title>');
|
||||||
|
|
@ -87,11 +87,17 @@ it('should have pages in persistent context', async ({ launchPersistent }, testI
|
||||||
await page.waitForLoadState('domcontentloaded');
|
await page.waitForLoadState('domcontentloaded');
|
||||||
await context.close();
|
await context.close();
|
||||||
const log = JSON.parse(fs.readFileSync(harPath).toString())['log'];
|
const log = JSON.parse(fs.readFileSync(harPath).toString())['log'];
|
||||||
|
let pageEntry;
|
||||||
|
if (browserName === 'webkit') {
|
||||||
// Explicit locale emulation forces a new page creation when
|
// Explicit locale emulation forces a new page creation when
|
||||||
// doing a new context.
|
// doing a new context.
|
||||||
// See https://github.com/microsoft/playwright/blob/13dd41c2e36a63f35ddef5dc5dec322052d670c6/packages/playwright-core/src/server/browserContext.ts#L232-L242
|
// See https://github.com/microsoft/playwright/blob/13dd41c2e36a63f35ddef5dc5dec322052d670c6/packages/playwright-core/src/server/browserContext.ts#L232-L242
|
||||||
expect(log.pages.length).toBe(2);
|
expect(log.pages.length).toBe(2);
|
||||||
const pageEntry = log.pages[1];
|
pageEntry = log.pages[1];
|
||||||
|
} else {
|
||||||
|
expect(log.pages.length).toBe(1);
|
||||||
|
pageEntry = log.pages[0];
|
||||||
|
}
|
||||||
expect(pageEntry.id).toBeTruthy();
|
expect(pageEntry.id).toBeTruthy();
|
||||||
expect(pageEntry.title).toBe('Hello');
|
expect(pageEntry.title).toBe('Hello');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue