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
test: add another test for browserContext.addInitScript (#2285)
Joel Einbinderb88fabab13d5
diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex 3756f52f28..cd97cde8f3 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -145,13 +145,11 @@ export class FFBrowser extends BrowserBase {export class FFBrowserContext extends BrowserContextBase {readonly _browser: FFBrowser;readonly _browserContextId: string | null;- private readonly _evaluateOnNewDocumentSources: string[];constructor(browser: FFBrowser, browserContextId: string | null, options: BrowserContextOptions) {super(browser, options);this._browser = browser;this._browserContextId = browserContextId;- this._evaluateOnNewDocumentSources = [];this._authenticateProxyViaHeader();}@@ -304,7 +302,6 @@ export class FFBrowserContext extends BrowserContextBase {async addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any) {const source = await helper.evaluationScript(script, arg);- this._evaluateOnNewDocumentSources.push(source);await this._browser._connection.send('Browser.addScriptToEvaluateOnNewDocument', { browserContextId: this._browserContextId || undefined, script: source });}diff --git a/test/popup.spec.js b/test/popup.spec.jsindex 9516dd8308..87db944cbe 100644--- a/test/popup.spec.js+++ b/test/popup.spec.js@@ -174,7 +174,7 @@ describe('window.open', function() {expect(intercepted).toBe(true);await context.close();});- it('should apply addInitScript from browser context', async function({browser, server}) {+ it('BrowserContext.addInitScript should apply to an in-process popup', async function({browser, server}) {const context = await browser.newContext();await context.addInitScript(() => window.injected = 123);const page = await context.newPage();@@ -186,6 +186,21 @@ describe('window.open', function() {await context.close();expect(injected).toBe(123);});+ it('BrowserContext.addInitScript should apply to a cross-process popup', async function({browser, server}) {+ const context = await browser.newContext();+ await context.addInitScript(() => window.injected = 123);+ const page = await context.newPage();+ await page.goto(server.EMPTY_PAGE);+ const [popup] = await Promise.all([+ page.waitForEvent('popup'),+ page.evaluate(url => window.open(url), server.CROSS_PROCESS_PREFIX + '/title.html'),+ ]);+ expect(await popup.evaluate('injected')).toBe(123);+ await popup.reload();+ expect(await popup.evaluate('injected')).toBe(123);+ await context.close();+ });+it('should expose function from browser context', async function({browser, server}) {const context = await browser.newContext();await context.exposeFunction('add', (a, b) => a + b);