Karate supports the W3C WebDriver protocol and can be used to run tests on Sauce Labs.
The example in this folder demonstrates how to run a test on Sauce Labs using Karate. All you need is a Sauce Labs account and values such as the URL, user, key etc.
From your Sauce Labs dashboard, you can get the values you need from the quickstart guide for Selenium / Java. The main ones you need are the username
and accessKey
. Change the Sauce Labs URL if needed, based on which region you want to use.
All you need to do in Karate is perform the configure driver
step as per the documentation. Note how sauce:options
are added to the WebDriver "capabilities":
* def session = { capabilities: { alwaysMatch: { browserName: 'chrome', browserVersion: 'latest', platformName: 'Windows 11', 'sauce:options': '#(sauceOptions)' } } }
* configure driver = { type: 'chromedriver', start: false, webDriverSession: '#(session)', webDriverUrl: '#(sauceLabsUrl)' }
Of course you can change the browserVersion
and platformName
to suit your needs. You will have to ensure that the Karate driver type matches the browserName
, for example chromedriver
for chrome
. Refer to the Karate documentation for all possible types.
Also refer to the documentation of webDriverSession
and webDriverUrl
for more details.
Note that for a typical test-suite, you will set variables via the karate-config.js
so you can switch browsers or between local and remote execution.