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(exposeFunction): implement context-level expose on firefox (#1478)
Pavel Feldman15ebe1c339d2
diff --git a/package.json b/package.jsonindex 38f4dd2784..9897b58043 100644--- a/package.json+++ b/package.json@@ -9,7 +9,7 @@"main": "index.js","playwright": {"chromium_revision": "751710",- "firefox_revision": "1049",+ "firefox_revision": "1050","webkit_revision": "1182"},"scripts": {diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex 7a2e67879b..5cd1220df8 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -288,7 +288,7 @@ export class FFBrowserContext extends BrowserContextBase {throw new Error(`Function "${name}" has been already registered`);const binding = new PageBinding(name, playwrightFunction);this._pageBindings.set(name, binding);- throw new Error('Not implemented');+ await this._browser._connection.send('Browser.addBinding', { browserContextId: this._browserContextId || undefined, name, script: binding.source });}async route(url: types.URLMatch, handler: network.RouteHandler): Promise<void> {diff --git a/src/firefox/ffPage.ts b/src/firefox/ffPage.tsindex c95c30eba8..68dc1893ee 100644--- a/src/firefox/ffPage.ts+++ b/src/firefox/ffPage.ts@@ -266,9 +266,7 @@ export class FFPage implements PageDelegate {}async exposeBinding(binding: PageBinding) {- await this._session.send('Page.addBinding', {name: binding.name});- await this._session.send('Page.addScriptToEvaluateOnNewDocument', {script: binding.source});- await Promise.all(this._page.frames().map(frame => frame.evaluate(binding.source).catch(debugError)));+ await this._session.send('Page.addBinding', { name: binding.name, script: binding.source });}didClose() {diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.jsindex 4ccc3a81b2..7e9ae9d716 100644--- a/test/browsercontext.spec.js+++ b/test/browsercontext.spec.js@@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF});describe('BrowserContext.exposeFunction', () => {- it.fail(FFOX)('should work', async({browser, server}) => {+ it('should work', async({browser, server}) => {const context = await browser.newContext();await context.exposeFunction('add', (a, b) => a + b);const page = await context.newPage();@@ -337,7 +337,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FFexpect(result).toEqual({ mul: 36, add: 13 });await context.close();});- it.fail(FFOX)('should throw for duplicate registrations', async({browser, server}) => {+ it('should throw for duplicate registrations', async({browser, server}) => {const context = await browser.newContext();await context.exposeFunction('foo', () => {});await context.exposeFunction('bar', () => {});@@ -351,7 +351,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FFexpect(error.message).toBe('Function "baz" has been already registered in one of the pages');await context.close();});- it.fail(FFOX)('should be callable from-inside addInitScript', async({browser, server}) => {+ it('should be callable from-inside addInitScript', async({browser, server}) => {const context = await browser.newContext();let args = [];await context.exposeFunction('woof', function(arg) {diff --git a/test/popup.spec.js b/test/popup.spec.jsindex 349dae590c..75dd5edce8 100644--- a/test/popup.spec.js+++ b/test/popup.spec.js@@ -166,7 +166,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, WEawait context.close();expect(injected).toBe(123);});- it.fail(FFOX)('should expose function from browser context', async function({browser, server}) {+ it('should expose function from browser context', async function({browser, server}) {const context = await browser.newContext();await context.exposeFunction('add', (a, b) => a + b);const page = await context.newPage();