BanksySan
BanksySan

Reputation: 28540

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

Upvotes: 7

Views: 4988

Answers (2)

Jitendra Khedar
Jitendra Khedar

Reputation: 129

To initialize the webDriver use this:

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

Now test the site, whatever you need, lets say you need google:

webDriver.get("http://www.google.com");

Upvotes: 0

Ross Rowe
Ross Rowe

Reputation: 397

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.

Upvotes: 15

Related Questions