Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(firefox): bump and use context setters (#2194)
Dmitry Gozman28845e5cccd4
diff --git a/packages/playwright-firefox/browsers.json b/packages/playwright-firefox/browsers.jsonindex 22cf7a0649..5521308109 100644--- a/packages/playwright-firefox/browsers.json+++ b/packages/playwright-firefox/browsers.json@@ -2,7 +2,7 @@"browsers": [{"name": "firefox",- "revision": "1093"+ "revision": "1094"}]}diff --git a/packages/playwright/browsers.json b/packages/playwright/browsers.jsonindex 26ccfed9b5..6f6a94fc65 100644--- a/packages/playwright/browsers.json+++ b/packages/playwright/browsers.json@@ -6,7 +6,7 @@},{"name": "firefox",- "revision": "1093"+ "revision": "1094"},{"name": "webkit",diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex 1d4532e768..7dc1ce1331 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -70,39 +70,9 @@ export class FFBrowser extends BrowserBase {async newContext(options: BrowserContextOptions = {}): Promise<BrowserContext> {options = validateBrowserContextOptions(options);- let viewport;- if (options.viewport) {- // TODO: remove isMobile from the protocol?- if (options.isMobile)- throw new Error('options.isMobile is not supported in Firefox');- viewport = {- viewportSize: { width: options.viewport.width, height: options.viewport.height },- deviceScaleFactor: options.deviceScaleFactor || 1,- isMobile: false,- hasTouch: !!options.hasTouch,- };- } else if (options.viewport !== null) {- viewport = {- viewportSize: { width: 1280, height: 720 },- deviceScaleFactor: 1,- isMobile: false,- hasTouch: false,- };- }- const { browserContextId } = await this._connection.send('Browser.createBrowserContext', {- userAgent: options.userAgent,- bypassCSP: options.bypassCSP,- ignoreHTTPSErrors: options.ignoreHTTPSErrors,- javaScriptDisabled: options.javaScriptEnabled === false ? true : undefined,- viewport,- locale: options.locale,- timezoneId: options.timezoneId,- removeOnDetach: true,- downloadOptions: {- behavior: options.acceptDownloads ? 'saveToDisk' : 'cancel',- downloadsDir: this._downloadsPath,- },- });+ if (options.isMobile)+ throw new Error('options.isMobile is not supported in Firefox');+ const { browserContextId } = await this._connection.send('Browser.createBrowserContext', { removeOnDetach: true });const context = new FFBrowserContext(this, browserContextId, options);await context._initialize();this._contexts.set(browserContextId, context);@@ -187,18 +157,50 @@ export class FFBrowserContext extends BrowserContextBase {}async _initialize() {+ const browserContextId = this._browserContextId || undefined;+ const promises: Promise<any>[] = [+ this._browser._connection.send('Browser.setDownloadOptions', {+ browserContextId,+ downloadOptions: {+ behavior: this._options.acceptDownloads ? 'saveToDisk' : 'cancel',+ downloadsDir: this._browser._downloadsPath,+ },+ }),+ ];+ if (this._options.viewport) {+ const viewport = {+ viewportSize: { width: this._options.viewport.width, height: this._options.viewport.height },+ deviceScaleFactor: this._options.deviceScaleFactor || 1,+ };+ promises.push(this._browser._connection.send('Browser.setDefaultViewport', { browserContextId, viewport }));+ }+ if (this._options.hasTouch)+ promises.push(this._browser._connection.send('Browser.setTouchOverride', { browserContextId, hasTouch: true }));+ if (this._options.userAgent)+ promises.push(this._browser._connection.send('Browser.setUserAgentOverride', { browserContextId, userAgent: this._options.userAgent }));+ if (this._options.bypassCSP)+ promises.push(this._browser._connection.send('Browser.setBypassCSP', { browserContextId, bypassCSP: true }));+ if (this._options.ignoreHTTPSErrors)+ promises.push(this._browser._connection.send('Browser.setIgnoreHTTPSErrors', { browserContextId, ignoreHTTPSErrors: true }));+ if (this._options.javaScriptEnabled === false)+ promises.push(this._browser._connection.send('Browser.setJavaScriptDisabled', { browserContextId, javaScriptDisabled: true }));+ if (this._options.locale)+ promises.push(this._browser._connection.send('Browser.setLocaleOverride', { browserContextId, locale: this._options.locale }));+ if (this._options.timezoneId)+ promises.push(this._browser._connection.send('Browser.setTimezoneOverride', { browserContextId, timezoneId: this._options.timezoneId }));if (this._options.permissions)- await this.grantPermissions(this._options.permissions);+ promises.push(this.grantPermissions(this._options.permissions));if (this._options.extraHTTPHeaders || this._options.locale)- await this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {});+ promises.push(this.setExtraHTTPHeaders(this._options.extraHTTPHeaders || {}));if (this._options.httpCredentials)- await this.setHTTPCredentials(this._options.httpCredentials);+ promises.push(this.setHTTPCredentials(this._options.httpCredentials));if (this._options.geolocation)- await this.setGeolocation(this._options.geolocation);+ promises.push(this.setGeolocation(this._options.geolocation));if (this._options.offline)- await this.setOffline(this._options.offline);+ promises.push(this.setOffline(this._options.offline));if (this._options.colorScheme)- await this._setColorScheme(this._options.colorScheme);+ promises.push(this._browser._connection.send('Browser.setColorScheme', { browserContextId, colorScheme: this._options.colorScheme }));+ await Promise.all(promises);}_ffPages(): FFPage[] {@@ -294,10 +296,6 @@ export class FFBrowserContext extends BrowserContextBase {await this._browser._connection.send('Browser.setOnlineOverride', { browserContextId: this._browserContextId || undefined, override: offline ? 'offline' : 'online' });}- async _setColorScheme(colorScheme?: types.ColorScheme): Promise<void> {- await this._browser._connection.send('Browser.setColorScheme', { browserContextId: this._browserContextId || undefined, colorScheme });- }-async setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void> {this._options.httpCredentials = httpCredentials || undefined;await this._browser._connection.send('Browser.setHTTPCredentials', { browserContextId: this._browserContextId || undefined, credentials: httpCredentials });diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.jsindex 31a526a9c8..295da1fdaa 100644--- a/test/browsercontext.spec.js+++ b/test/browsercontext.spec.js@@ -324,10 +324,11 @@ describe('BrowserContext.exposeFunction', () => {await context.exposeFunction('add', (a, b) => a + b);const page = await context.newPage();await page.exposeFunction('mul', (a, b) => a * b);+ await context.exposeFunction('sub', (a, b) => a - b);const result = await page.evaluate(async function() {- return { mul: await mul(9, 4), add: await add(9, 4) };+ return { mul: await mul(9, 4), add: await add(9, 4), sub: await sub(9, 4) };});- expect(result).toEqual({ mul: 36, add: 13 });+ expect(result).toEqual({ mul: 36, add: 13, sub: 5 });await context.close();});it('should throw for duplicate registrations', async({browser, server}) => {diff --git a/test/launcher.spec.js b/test/launcher.spec.jsindex 98e07f938c..093e0296fa 100644--- a/test/launcher.spec.js+++ b/test/launcher.spec.js@@ -52,7 +52,7 @@ describe('Playwright', function() {expect(waitError.message).toContain('Failed to launch');});it('should handle timeout', async({browserType, defaultBrowserOptions}) => {- const options = { ...defaultBrowserOptions, timeout: 1000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 2000)) };+ const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };const error = await browserType.launch(options).catch(e => e);expect(error.message).toBe('Waiting for the browser to launch failed: timeout exceeded. Re-run with the DEBUG=pw:browser* env variable to see the debug log.');});@@ -100,7 +100,7 @@ describe('Playwright', function() {});it('should handle timeout', async({browserType, defaultBrowserOptions}) => {const userDataDir = await makeUserDataDir();- const options = { ...defaultBrowserOptions, timeout: 1000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 2000)) };+ const options = { ...defaultBrowserOptions, timeout: 5000, __testHookBeforeCreateBrowser: () => new Promise(f => setTimeout(f, 6000)) };const error = await browserType.launchPersistentContext(userDataDir, options).catch(e => e);expect(error.message).toBe('Waiting for the browser to launch failed: timeout exceeded. Re-run with the DEBUG=pw:browser* env variable to see the debug log.');await removeUserDataDir(userDataDir);