Sauce Labs now supports the W3C WebDriver-compliant capabilities and protocol featured in Selenium versions 3.11 and higher. Please note that some extended capabilities are not backwards-compatible with versions prior to 4.0. This article will help ensure that your tests are W3C WebDriver-compliant and can successfully execute on Sauce Labs.
We early adopted the W3C WebDriver specification when it achieved the W3C standard level as the automation protocol for web browsers. As browser vendors update to support W3C WebDriver and shift away from JSON Wire Protocol (JWP), it’s important to update your tests accordingly.
See the following sections for more information:
Browser | W3C Support | JWP Support |
---|---|---|
Chrome | 75 and above | Still supported |
Firefox | 55 and above | Still supported |
Safari | 12 and above | Removed in 12.1 |
Edge | All | Still supported |
Internet Explorer | All | Still supported |
To ensure W3C WebDriver compliance, you'll need to:
Switch completely from using legacy JWP desired capabilities to the new W3C WebDriver capabilities. Note that their naming conventions are slightly different – for example:
JWP (legacy) | W3C (new) |
---|---|
platform | platformName |
version | browserVersion |
For more information on W3C WebDriver-compliant capabilities, head to the official W3C recommendation website.
Include our custom sauce:options
capabilities (e.g., name
, build
) in your Sauce Labs test scripts, bundled together, as seen in this example:
browserName: 'firefox', platformName: 'macOS 10.15', browserVersion: 'latest' sauce:options: { name: 'My test name', build: 'My build', username: "SAUCE_USERNAME", accessKey: "SAUCE_ACCESS_KEY" seleniumVersion: "3.141.59" } |
More information: Test Configuration Options. |
Below are a couple of mobile and web test script examples you can use to get up and running quickly:
The following browser versions are compatible with the W3C WebDriver protocol:
By default, Sauce Labs uses older versions of Firefox, IE, and Safari. This is important to know since newer commands and configurations may not be supported in those versions.
chromeOptions()
For tests on Google Chrome versions 74 and lower, the W3C WebDriver capability must be set as an experimental option. ChromeDriver version 75 runs in W3C WebDriver standard compliant mode by default, so setting this capability won't be necessary in the future. Here's an example:
ChromeOptions chOpts = new ChromeOptions(); chOpts.setExperimentalOption("w3c", true); |
NOTE: w3c
must be set as a boolean value (e.g., true
in Java and True
in Python) – not a string (e.g., "true").
Here's how to verify if your tests are running under the new W3C WebDriver protocol:
Post
command, which will be Post /session
.Parameters
section, check the capabilities that are used in the test. Parameters
section begins with capabilities
, you're running the new W3C WebDriver-compliant versiondesiredCapabilities
, you're running the legacy, non-W3C WebDriver versionThere are some changes to specific Selenium language bindings you should be aware of when migrating to the W3C WebDriver protocol. Here is an example:
Using legacy formatting in Selenium 3.11+ script will yield the following message:
Example: Legacy, with |
DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("username", "someuser"); caps.setCapability("accessKey", "00000000-0000-0000-0000-000000000000"); caps.setCapability("name", "my test case"); caps.setCapability("browser", "firefox"); caps.setCapability("platform", "Windows 10"); caps.setCapability("version", "latest"); WebDriver driver = new RemoteWebDriver(new URL("https://ondemand.saucelabs.com/wd/hub"), caps); |
Select a code snippet below in the programming language of your choice, then follow the instructions. You can find more sample code in the Sauce Labs training repository on GitHub.
|
Here are some things to keep in mind when configuring your test script capabilities.
It's important not to mix W3C WebDriver-compliant capabilities with legacy JWP capabilities. This will result in a system error when you're spinning up a WebDriver session:
selenium.common.exceptions.WebDriverException: Message: Misconfigured -- Mixed Capabilities Error. W3C keys (platformName/browserVersion) were detected alongside JWP keys (platform/version). To fix this, replace all JWP keys with W3C keys. The following desired capabilities were received: {'browserName': 'chrome', 'browserVersion': '80', 'platform': 'Windows'} See https://wiki.saucelabs.com/display/docs/w3c+capabilities+support for more details. |
To fix this particular error, you'd need to change platform
to platformName
and then change version
to browserVersion
:
browserName: 'chrome', platformName: 'Windows', browserVersion: '80' sauce:options: { name: 'My test name', build: 'My build', username: "SAUCE_USERNAME", accessKey: "SAUCE_ACCESS_KEY" seleniumVersion: "3.141.59" } |
sauce:options
capability