Skip to content

Support Selenium 4.0 Grid CDP for Devtools Service#6508

Merged
christian-bromann merged 3 commits intowebdriverio:mainfrom
dylanlive:se_4_cdp
Mar 6, 2021
Merged

Support Selenium 4.0 Grid CDP for Devtools Service#6508
christian-bromann merged 3 commits intowebdriverio:mainfrom
dylanlive:se_4_cdp

Conversation

@dylanlive
Copy link
Copy Markdown
Contributor

Proposed changes

Addresses #6470. This PR allows using the devtools service with Selenium 4.0 Grid (beta-1).

When creating a new session, Selenium 4.0 Beta 1 will respond with an endpoint that can be used to make direct websocket requests with (see below for example response).

Puppeteer takes that as browserWSEndpoint as described here.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

  1. I have read discussions that potentially in a future Se4 Beta, the structure of "se:options" may change. However, I figured we can at least get the ball rolling now and make tweaks as needed.

  2. The conditional precedence is very important in this PR. A response can have both se:options and the debuggerAddress that gets tacked on by Chromedriver.

Full response example here:

{
    "status": 0,
    "sessionId": "c8adfc6384648299d726d9c63d4e7a15",
    "value": {
        "acceptInsecureCerts": false,
        "browserName": "chrome",
        "browserVersion": "88.0.4324.182",
        "chrome": {
            "chromedriverVersion": "87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-refs/branch-heads/4280@{#355})",
            "userDataDir": "/var/folders/kx/c8_k_9q17qngwmlbc282nhc0bnj1_9/T/.com.google.Chrome.WKVL7Y"
        },
        "goog:chromeOptions": {
            "debuggerAddress": "localhost:52810"
        },
        "networkConnectionEnabled": false,
        "pageLoadStrategy": "normal",
        "platformName": "mac os x",
        "proxy": {},
        "se:options": {
            "cdp": "http://my.grid:5555/session/c8adfc6384648299d726d9c63d4e7a15/se/cdp"
        },
        "setWindowRect": true,
        "strictFileInteractability": false,
        "timeouts": {
            "implicit": 0,
            "pageLoad": 300000,
            "script": 30000
        },
        "unhandledPromptBehavior": "dismiss and notify",
        "webauthn:virtualAuthenticators": true
    }
}
  1. (just for note) I'm hoping [Selenium 4] [Grid] Se:Options CDP Endpoint Points to Node SeleniumHQ/selenium#9202 is addressed. Personally I prefer the Selenium Hub to proxy all cdp requests. Beta 1 currently returns a direct endpoint to the Node. However, I feel it would be irresponsible in this PR to hardcode the hub (via something like ws://${this.config.hostname}:${this.config.port}/session/${this.sessionId}/se/cdp, which works) instead of utilizing what is returned by Selenium.

Reviewers: @webdriverio/project-committers

@dylanlive
Copy link
Copy Markdown
Contributor Author

Not seeing where to sign the CLA in any of the contributor docs.

@L0tso
Copy link
Copy Markdown
Contributor

L0tso commented Feb 25, 2021

const cdpEndpoint = caps['se:options']?.cdp
if (cdpEndpoint) {
this.puppeteer = await puppeteer.connect({
browserWSEndpoint: cdpEndpoint
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make some hardcoded assumptions here, this could work with the docker images as described in #6470 (comment)

Something like:
ws://${this.config.hostname}:${this.config.port}/session/${this.sessionId}/se/cdp

Definitely not as slick though and more likely to break in a future update. Would be a temp bandaid until SeleniumHQ/selenium#9202 is addressed.

Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment but otherwise this looks good to me. Do you mind signing the CLA?

* Selenium 4.0 Specific
*/
'se:options'?: {
cdp?: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know more Selenium specific options we can add within this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to my knowledge

@dylanlive
Copy link
Copy Markdown
Contributor Author

Will get the CLA signed as soon as I'm able to

@christian-bromann
Copy link
Copy Markdown
Member

@dylanlive awesome! It would be also great if you could update your branch as I tweaked the pipline a bit. Thanks!

@christian-bromann
Copy link
Copy Markdown
Member

@dylanlive any chance to update the branch and sign the CLA? Would love to get this into the next v7.1 release.

Selenium 4 (beta-1) Grid supports CDP Websocket Requests, and returns the endpoint in the returned capabilities under {"se:options": { "cdp": "the_url" }}. This commit will utilize that endpoint (if returned in the capabilities) as the Puppeteer Websocket Endpoint.
@dylanlive
Copy link
Copy Markdown
Contributor Author

@christian-bromann CLA signed, thanks for your patience. Merged in the latest changes and applied the defaultViewport from #6487

Did a few quick tests as well with a Se4 Grid (confirmed working) and a Se3 Grid (confirmed not working, as expected).

As a suggestion, if you could add a link to the CLA in https://github.com/webdriverio/webdriverio/blob/main/CONTRIBUTING.md, I think that could have sped up the process in my case.

@christian-bromann
Copy link
Copy Markdown
Member

As a suggestion, if you could add a link to the CLA in https://github.com/webdriverio/webdriverio/blob/main/CONTRIBUTING.md, I think that could have sped up the process in my case.

Good idea, will make that change.

Thanks for the contribution!

@christian-bromann christian-bromann added the PR: New Feature 🚀 PRs that contain new features label Mar 6, 2021
Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This was referenced Mar 17, 2021
@tripuzv
Copy link
Copy Markdown

tripuzv commented Jun 21, 2023

I have a problem with debuggerAddress, cause I am using https instead of http. How to fix it?
When i use only host it returns to me HTTP Bad Request,
But if i use whole address with https it trying to connect next address http://https/json/version:

@christian-bromann
Copy link
Copy Markdown
Member

Why are you using https for a local Selenium server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wdio-devtools-service] Support CDP on Selenium 4 Grid

4 participants