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
browser(firefox): add screencast control methods to context (#3530)
Yury Semikhatsky73cd6ecef3ed
diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBERindex 65a581ef24..550e78d53a 100644--- a/browser_patches/firefox/BUILD_NUMBER+++ b/browser_patches/firefox/BUILD_NUMBER@@ -1,2 +1,2 @@-1160-Changed: [email protected] Thu Aug 13 23:10:17 PDT 2020+1161+Changed: [email protected] Wed Aug 19 11:51:52 PDT 2020diff --git a/browser_patches/firefox/juggler/TargetRegistry.js b/browser_patches/firefox/juggler/TargetRegistry.jsindex 105ec0702f..00980bc775 100644--- a/browser_patches/firefox/juggler/TargetRegistry.js+++ b/browser_patches/firefox/juggler/TargetRegistry.js@@ -198,7 +198,7 @@ class TargetRegistry {setViewportSizeForBrowser(browserContext.defaultViewportSize, tab.linkedBrowser, window);};- const onTabCloseListener = event => {+ const onTabCloseListener = async event => {const tab = event.target;const linkedBrowser = tab.linkedBrowser;const target = this._browserToTarget.get(linkedBrowser);@@ -497,6 +497,7 @@ class BrowserContext {this.ignoreHTTPSErrors = undefined;this.downloadOptions = undefined;this.defaultViewportSize = undefined;+ this.screencastOptions = undefined;this.scriptsToEvaluateOnNewDocument = [];this.bindings = [];this.settings = {};@@ -684,6 +685,10 @@ class BrowserContext {}return result;}++ setScreencastOptions(options) {+ this.screencastOptions = options;+ }}function dirPath(path) {diff --git a/browser_patches/firefox/juggler/protocol/BrowserHandler.js b/browser_patches/firefox/juggler/protocol/BrowserHandler.jsindex 50e7a9ba38..9b960add61 100644--- a/browser_patches/firefox/juggler/protocol/BrowserHandler.js+++ b/browser_patches/firefox/juggler/protocol/BrowserHandler.js@@ -64,11 +64,11 @@ class BrowserHandler {this._createdBrowserContextIds.delete(browserContextId);}- dispose() {+ async dispose() {helper.removeListeners(this._eventListeners);for (const [target, session] of this._attachedSessions) {target.disconnectSession(session);- this._dispatcher.destroySession(session);+ await this._dispatcher.destroySession(session);}this._attachedSessions.clear();for (const browserContextId of this._createdBrowserContextIds) {@@ -99,12 +99,12 @@ class BrowserHandler {sessions.push(session);}- _onTargetDestroyed(target) {+ async _onTargetDestroyed(target) {const session = this._attachedSessions.get(target);if (!session)return;this._attachedSessions.delete(target);- this._dispatcher.destroySession(session);+ await this._dispatcher.destroySession(session);this._session.emitEvent('Browser.detachedFromTarget', {sessionId: session.sessionId(),targetId: target.id(),@@ -184,6 +184,10 @@ class BrowserHandler {await this._targetRegistry.browserContextForId(browserContextId).applySetting('colorScheme', nullToUndefined(colorScheme));}+ async setScreencastOptions({browserContextId, dir, width, height, scale}) {+ await this._targetRegistry.browserContextForId(browserContextId).setScreencastOptions({dir, width, height, scale});+ }+async setUserAgentOverride({browserContextId, userAgent}) {await this._targetRegistry.browserContextForId(browserContextId).applySetting('userAgent', nullToUndefined(userAgent));}diff --git a/browser_patches/firefox/juggler/protocol/Dispatcher.js b/browser_patches/firefox/juggler/protocol/Dispatcher.jsindex 2f0413f981..c90903fcb4 100644--- a/browser_patches/firefox/juggler/protocol/Dispatcher.js+++ b/browser_patches/firefox/juggler/protocol/Dispatcher.js@@ -29,9 +29,9 @@ class Dispatcher {return session;}- destroySession(session) {- session.dispose();+ async destroySession(session) {this._sessions.delete(session.sessionId());+ await session.dispose();}_dispose() {@@ -108,13 +108,15 @@ class ProtocolSession {this._handlers.set(domainName, handler);}- dispose() {+ async dispose() {+ const promises = [];for (const [domainName, handler] of this._handlers) {if (typeof handler.dispose !== 'function')throw new Error(`Handler for "${domainName}" domain does not define |dispose| method!`);- handler.dispose();+ promises.push(handler.dispose());}this._handlers.clear();+ await Promise.all(promises);this._dispatcher = null;}diff --git a/browser_patches/firefox/juggler/protocol/PageHandler.js b/browser_patches/firefox/juggler/protocol/PageHandler.jsindex 4deb05fba6..523f12d41e 100644--- a/browser_patches/firefox/juggler/protocol/PageHandler.js+++ b/browser_patches/firefox/juggler/protocol/PageHandler.js@@ -6,6 +6,7 @@const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js');const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");+const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");const Cc = Components.classes;const Ci = Components.interfaces;@@ -132,13 +133,19 @@ class PageHandler {this._session.emitEvent('Page.crashed', {});}),]);++ const options = this._pageTarget.browserContext().screencastOptions;+ if (options) {+ const file = OS.Path.join(options.dir, helper.generateId() + '.webm');+ await this.startVideoRecording(Object.assign({file}, options));+ }}- dispose() {+ async dispose() {this._contentPage.dispose();helper.removeListeners(this._eventListeners);if (this._videoSessionId !== -1)- this.stopVideoRecording().catch(e => dump(`stopVideoRecording failed:\n${e}\n`));+ await this.stopVideoRecording().catch(e => dump(`stopVideoRecording failed:\n${e}\n`));}async setViewportSize({viewportSize}) {@@ -304,6 +311,7 @@ class PageHandler {const rect = this._pageTarget.linkedBrowser().getBoundingClientRect();const devicePixelRatio = this._pageTarget._window.devicePixelRatio;this._videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, devicePixelRatio * rect.top);+ this._session.emitEvent('Page.screencastStarted', {uid: '' + this._videoSessionId, file});}async stopVideoRecording() {@@ -312,6 +320,7 @@ class PageHandler {const videoSessionId = this._videoSessionId;this._videoSessionId = -1;const screencast = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);+ const session = this._session;const result = new Promise(resolve =>Services.obs.addObserver(function onStopped(subject, topic, data) {if (videoSessionId != data)@@ -319,6 +328,8 @@ class PageHandler {Services.obs.removeObserver(onStopped, 'juggler-screencast-stopped');resolve();++ session.emitEvent('Page.screencastStopped', {uid: '' + videoSessionId});}, 'juggler-screencast-stopped'));screencast.stopVideoRecording(videoSessionId);diff --git a/browser_patches/firefox/juggler/protocol/Protocol.js b/browser_patches/firefox/juggler/protocol/Protocol.jsindex 5a6822694e..f47b73e449 100644--- a/browser_patches/firefox/juggler/protocol/Protocol.js+++ b/browser_patches/firefox/juggler/protocol/Protocol.js@@ -407,6 +407,15 @@ const Browser = {colorScheme: t.Nullable(t.Enum(['dark', 'light', 'no-preference'])),},},+ 'setScreencastOptions': {+ params: {+ browserContextId: t.Optional(t.String),+ dir: t.String,+ width: t.Number,+ height: t.Number,+ scale: t.Optional(t.Number),+ },+ },},};@@ -640,6 +649,13 @@ const Page = {workerId: t.String,message: t.String,},+ 'screencastStarted': {+ uid: t.String,+ file: t.String,+ },+ 'screencastStopped': {+ uid: t.String,+ },},methods: {