From a7ef1da5e9ed73cbdf1e5051b6557ebbceb10197 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 18 Feb 2022 14:44:15 -0800 Subject: [PATCH] fix(selenium): support MicrosoftEdge (#12235) --- docs/src/selenium-grid.md | 12 +++++++----- .../playwright-core/src/server/chromium/chromium.ts | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/src/selenium-grid.md b/docs/src/selenium-grid.md index 3c83c63a27..301cc41d46 100644 --- a/docs/src/selenium-grid.md +++ b/docs/src/selenium-grid.md @@ -3,7 +3,9 @@ id: selenium-grid title: "Selenium Grid" --- -Playwright can connect to [Selenium Grid Hub](https://www.selenium.dev/documentation/grid/) that runs **Selenium 4** to launch **Chrome** browser, instead of running browser on the local machine. To enable this mode, set `SELENIUM_REMOTE_URL` environment variable pointing to your Selenium Grid Hub. +## Selenium 4 + +Playwright can connect to [Selenium Grid Hub](https://www.selenium.dev/documentation/grid/) that runs Selenium 4 to launch **Chrome** or **Microsoft Edge** browser, instead of running browser on the local machine. To enable this mode, set `SELENIUM_REMOTE_URL` environment variable pointing to your Selenium Grid Hub. ```bash js # Playwright Test @@ -59,8 +61,8 @@ SELENIUM_REMOTE_URL=http://internal.grid:4444/wd/hub SELENIUM_REMOTE_CAPABILITIE SELENIUM_REMOTE_URL=http://internal.grid:4444/wd/hub SELENIUM_REMOTE_CAPABILITIES="{'mygrid:options':{os:'windows',username:'John',password:'secure'}}" dotnet test ``` -:::note -Internally, Playwright connects to the browser using [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) websocket. Selenium 4 hub exposes this capability. +## Selenium 3 -Selenium 3 is supported in a best-effort manner. Grid nodes must be directly accessible from the machine that runs Playwright. -::: +Internally, Playwright connects to the browser using [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) websocket. Selenium 4 hub exposes this capability, while Selenium 3 does not. + +This means that Selenium 3 is supported in a best-effort manner, where Playwright tries to connect to the grid node directly. Grid nodes must be directly accessible from the machine that runs Playwright. diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index 42bf63147c..03f20c3659 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -156,7 +156,8 @@ export class Chromium extends BrowserType { const args = this._innerDefaultArgs(options); args.push('--remote-debugging-port=0'); - let desiredCapabilities = { 'browserName': 'chrome', 'goog:chromeOptions': { args } }; + const isEdge = options.channel && options.channel.startsWith('msedge'); + let desiredCapabilities = { 'browserName': isEdge ? 'MicrosoftEdge' : 'chrome', 'goog:chromeOptions': { args } }; try { if (process.env.SELENIUM_REMOTE_CAPABILITIES) { const parsed = JSON.parse(process.env.SELENIUM_REMOTE_CAPABILITIES);