mantoni / min-webdriver

Pipe scripts to browsers using the Selenium WebDriver protocol
MIT License
25 stars 11 forks source link

Support the W3C WebDriver-compliant capabilities and protocol in Selenium > 3.10 #31

Open fatso83 opened 3 years ago

fatso83 commented 3 years ago

All newer browsers support the W3C WebDriver-compliant capabilities and protocol featured in Selenium versions 3.11 and higher. As for the case of Safari, it has actually dropped support for the JSON Wire Protocol already (starting with Safari 12.1).

Background article on Sauce Labs: https://wiki.saucelabs.com/display/DOCS/W3C+Capabilities+Support

I think we should consider either fully converting to this new protocol (as the old will be dropped) or support it using a flag. AFAIK it seems we only need to change these lines: https://github.com/mantoni/min-webdriver/blob/master/lib/driver.js#L202-L224

It might not be more than a few prop renames, it seems. (Famous last words)

fatso83 commented 3 years ago

So, basically I was not able to get this going. No matter what I tried I did not get past this:

POST /wd/hub/session

Unexpected HTTP status: 401 Unauthorized

transfer-encoding: chunked
date: Tue, 25 May 2021 10:59:25 GMT
connection: close
content-type: text/plain
www-authenticate: Basic realm="Sauce OnDemand"
server: monocle/0.42

Response Status Code: 13
Response Message:
    Misconfigured -- Sauce Labs Authentication Error.
    You used username 'None' and access key 'None' to authenticate, which are not valid Sauce Labs credentials.

    The following desired capabilities were received:
    {'accessKey': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXbd2851f8',
     'browserName': 'Safari',
     'javascriptEnabled': True,
     'platformName': 'macOS',
     'username': 'sinonjs'}

Error: Unexpected HTTP status: 401 Unauthorized

I linked up this project to sinon and used that as the driver. Basically, I am not sure what the "wire protocol" looks like, but I know the structure is a bit different than simply prop renaming, after inspecting the actual webdriver library for Node.

I first had a look at this: https://github.com/saucelabs-training/w3c-examples/blob/master/node/mocha/test/chrome-w3c-example-test.js

Then inspected https://github.com/SeleniumHQ/selenium/blob/7b832ead31f41304f0fa73ef4c6902c2ef1651e6/javascript/node/selenium-webdriver/lib/webdriver.js#L712

Saw that the capabilities now belonged in a different prop, and also under a new sub-prop. Only a subset of the previous props are allowed there, which explains why the username and access key are not recognized.

So it seems I need to change a bit more than just https://github.com/mantoni/min-webdriver/blob/master/lib/driver.js#L202-L224 ...

I guess using the offical selenium-webdriver to drive this is out of the question? It would probably handle most of the low-level details, but then again, I guess there is a specific reason why @mantoni chose to reimplement this 😃

mantoni commented 3 years ago

Thank you for digging into this. I havn't found the time myself, unfortunately.

There is only one reasons why I implemented the protocol myself: The selenium-webdriver package has 676 kB, and I needed only a handfull of requests. This package is just 35 kB.

At the time, implementing the protocol was simple enough, but it might have become more complicated over time. I'm not attached to this project and the way it works or how "heavy" it is anymore. The name prefix "min-" may not accurate anymore, if it depends on selenium-webdriver 😆.

So having said that, feel free to use whatever library makes your life easy. If you want to do this completly differently, go ahead, I'm also happy to include a different dependency in mochify. Whatever works.