diff --git a/src/browser/new-browser.js b/src/browser/new-browser.js index 011400e08..27773e3f6 100644 --- a/src/browser/new-browser.js +++ b/src/browser/new-browser.js @@ -8,6 +8,7 @@ const Browser = require("./browser"); const signalHandler = require("../signal-handler"); const history = require("./history"); const logger = require("../utils/logger"); +const RuntimeConfig = require("../config/runtime-config"); const DEFAULT_PORT = 4444; @@ -92,6 +93,7 @@ module.exports = class NewBrowser extends Browser { const config = this._config; const gridUri = new URI(config.gridUrl); const capabilities = this._extendCapabilities(config); + const { devtools } = RuntimeConfig.getInstance(); const options = { protocol: gridUri.protocol(), @@ -100,7 +102,7 @@ module.exports = class NewBrowser extends Browser { path: gridUri.path(), queryParams: this._getQueryParams(gridUri.query()), capabilities, - automationProtocol: config.automationProtocol, + automationProtocol: devtools ? "devtools" : config.automationProtocol, connectionRetryTimeout: config.sessionRequestTimeout || config.httpTimeout, connectionRetryCount: 0, // hermione has its own advanced retries baseUrl: config.baseUrl, diff --git a/src/cli/index.js b/src/cli/index.js index 1867e9254..3d44fc367 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -67,6 +67,7 @@ exports.run = () => { ) .option("--repl-before-test [type]", "open repl interface before test run", Boolean, false) .option("--repl-on-fail [type]", "open repl interface on test fail only", Boolean, false) + .option("--devtools", "switches the browser to the devtools mode with using CDP protocol") .arguments("[paths...]") .action(async paths => { try { @@ -82,6 +83,7 @@ exports.run = () => { repl, replBeforeTest, replOnFail, + devtools, } = program; await handleRequires(requireModules); @@ -99,6 +101,7 @@ exports.run = () => { beforeTest: replBeforeTest, onFail: replOnFail, }, + devtools: devtools || false, }); process.exit(isTestsSuccess ? 0 : 1); diff --git a/src/hermione.ts b/src/hermione.ts index cadb8e352..d9ba2ac05 100644 --- a/src/hermione.ts +++ b/src/hermione.ts @@ -31,6 +31,7 @@ interface RunOpts { beforeTest: boolean; onFail: boolean; }; + devtools: boolean; } interface ReadTestsOpts extends Pick { @@ -69,12 +70,13 @@ export class Hermione extends BaseHermione { requireModules, inspectMode, replMode, + devtools, reporters = [], }: Partial = {}, ): Promise { validateUnknownBrowsers(browsers, _.keys(this._config.browsers)); - RuntimeConfig.getInstance().extend({ updateRefs, requireModules, inspectMode, replMode }); + RuntimeConfig.getInstance().extend({ updateRefs, requireModules, inspectMode, replMode, devtools }); if (replMode?.enabled) { this._config.system.mochaOpts.timeout = 0; diff --git a/test/src/browser/new-browser.js b/test/src/browser/new-browser.js index 0f714a5e5..1eaf2954f 100644 --- a/test/src/browser/new-browser.js +++ b/test/src/browser/new-browser.js @@ -5,8 +5,9 @@ const webdriverio = require("webdriverio"); const logger = require("src/utils/logger"); const signalHandler = require("src/signal-handler"); const history = require("src/browser/history"); -const { WEBDRIVER_PROTOCOL, SAVE_HISTORY_MODE } = require("src/constants/config"); +const { WEBDRIVER_PROTOCOL, DEVTOOLS_PROTOCOL, SAVE_HISTORY_MODE } = require("src/constants/config"); const { X_REQUEST_ID_DELIMITER } = require("src/constants/browser"); +const RuntimeConfig = require("src/config/runtime-config"); const { mkNewBrowser_: mkBrowser_, mkSessionStub_ } = require("./utils"); describe("NewBrowser", () => { @@ -17,6 +18,8 @@ describe("NewBrowser", () => { session = mkSessionStub_(); sandbox.stub(logger); sandbox.stub(webdriverio, "remote").resolves(session); + + sandbox.stub(RuntimeConfig, "getInstance").returns({ devtools: undefined }); }); afterEach(() => sandbox.restore()); @@ -42,6 +45,14 @@ describe("NewBrowser", () => { }); }); + it("should use devtools protocol if hermione runs in devtools mode", async () => { + RuntimeConfig.getInstance.returns({ devtools: true }); + + await mkBrowser_().init(); + + assert.calledWithMatch(webdriverio.remote, { automationProtocol: DEVTOOLS_PROTOCOL }); + }); + it("should pass default port if it is not specified in grid url", async () => { await mkBrowser_({ gridUrl: "http://some-host/some-path" }).init(); diff --git a/test/src/cli/index.js b/test/src/cli/index.js index e21f28925..9426dade7 100644 --- a/test/src/cli/index.js +++ b/test/src/cli/index.js @@ -280,4 +280,10 @@ describe("cli", () => { }); }); }); + + it("should turn on devtools mode from cli", async () => { + await run_("--devtools"); + + assert.calledWithMatch(Hermione.prototype.run, any, { devtools: true }); + }); }); diff --git a/test/src/hermione.js b/test/src/hermione.js index 4f90360ef..547f62288 100644 --- a/test/src/hermione.js +++ b/test/src/hermione.js @@ -188,6 +188,7 @@ describe("hermione", () => { replMode: { enabled: true, }, + devtools: true, }); assert.calledOnce(RuntimeConfig.getInstance); @@ -196,6 +197,7 @@ describe("hermione", () => { requireModules: ["foo"], inspectMode: { inspect: true }, replMode: { enabled: true }, + devtools: true, }); assert.callOrder(RuntimeConfig.getInstance, Runner.create); });