7

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

Aman Gupta
  • 2,831
  • 3
  • 28
  • 55
BanksySan
  • 24,077
  • 27
  • 94
  • 189

2 Answers2

15

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.

Ross Rowe
  • 397
  • 4
  • 9
  • Does this mean my test need to be run on the same box as SauceConnect? – BanksySan Mar 23 '13 at 04:02
  • 1
    No, if Sauce Connect is launched on another server, then you just need to reference that server URL, eg. new URL("http://" + username + ":" + accesskey + "@some.other.host:4445/wd/hub") – Ross Rowe Mar 23 '13 at 04:35
  • 1
    Thanks for the answer. i should note that the SauceLabs online documentation does not give this answer in this much detail. Thanks. – djangofan Mar 30 '15 at 22:39
  • Saucelabs online documentation still doesn't have this info even after 3 years. Thanks for detailed info – vikramvi Nov 18 '17 at 06:40
0

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");