Search code examples
webdriversaucelabs

Where are the code examples for connecting your tests to Sauce Connect?


I've read the: Sauce Labs: Connect page

and looked through Internet but I can't find any documentation on how to convert my Selenium tests to use Sauce Connect.

Could someone point me in the right direction?

Cheers

Dave


Solution

  • By default, Sauce Connect will be available via http://localhost:4445, so you should just need to change your tests from:

    WebDriver driver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities);
    

    to:

    WebDriver driver = new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@localhost:4445/wd/hub"), capabilities);
    

    You shouldn't need to change your actual test logic when running tests with Sauce Connect.

    I've created a demo project, which primarily demonstrates how to construct tests to work with the Sauce plugins for Jenkins and Bamboo, but also includes a sample SauceConnectTest which asserts that tests can be run against a local website with Sauce Labs using Sauce Connect.