The New Sauce Labs Integration

Sauce_Labs_Logo

In our previous post, we showed the new support for running tests in the cloud. We have now extended our API to also include support for the superb Sauce Labs service. Using Sauce, you no longer have to worry about setting up and maintaining your own virtual machines. Running tests in the Sauce infrastructure is seamless and only requires you to perform a few initial steps.

Registering With Sauce

When registering an account in Sauce Labs, you will receive a user name (displayed in the right top corner after logging in) and an API key which can be found in the left-bottom corner of the “Account” page. Later in this post we will refer to these as “Sauce Labs username” and “Sauce Labs access key” (or Sauce Labs API key).

Quick And Easy Testing

Assuming your local web server is configured to listen at host “localhost” on port 80, all you need to be able to launch your test suite in the cloud is to sign up for the SauceLabs trial and run the following command:

__SIESTA_DIR__/bin/webdriver http://localhost/myproject/tests/harness.html –saucelabs SL_USERNAME,SL_KEY
–cap browserName=firefox –cap platform=windows

That’s all, the only difference from a normal Siesta automated launch is the “–saucelabs” option, which is a shortcut performing a few additional actions. We’ll examine what happens under the hood later in this post. Note how we have specified the desired OS/browser combination using the “–cap” switch (it specifies the remote webdriver capability). For a full list of supported capabilities please refer to http://code.google.com/p/selenium/wiki/DesiredCapabilities.

If your webserver listens on a different host (mylocalhost for example) or port (8888), then the “–saucelabs” option should look like:

–saucelabs SL_USERNAME,SL_KEY,mylocalhost,8888

Under The Hood

Let’s examine what happens under the hood when we use the “–saucelabs” shortcut option. In fact, we don’t have to use this shortcut option and can perform all the steps listed below manually.

1) The first thing that happens is that Siesta establishes a local tunnel from your machine to the Sauce Labs server, using the Sauce Labs binaries. You can do this step manually by using the batch file in the Siesta package:

__SIESTA_DIR__/bin/sc -u SL_USERNAME -k SL_API_KEY

When launched successfully, you should see the following text:

11 Aug 13:21:22 – Sauce Connect 4.3, build 1283 399e76d
11 Aug 13:21:22 – Using CA certificate bundle /etc/ssl/certs/ca-certificates.crt.
…..
11 Aug 13:22:12 – Starting Selenium listener…
11 Aug 13:22:15 – Sauce Connect is up, you may start your tests.
11 Aug 13:22:15 – Connection established.

2) The “–host” option is set to point to the Sauce Labs server, based on your username and access key:

–host=”http://SL_USERNAME:SL_API_KEY@ondemand.saucelabs.com:80/wd/hub”

To sum up, instead of using the “–saucelabs” shortcut option, we could:

– launch the tunnel manually:

__SIESTA_DIR__/bin/sc -u SL_USERNAME -k SL_API_KEY

– specify the command as:

__SIESTA_DIR__/bin/webdriver http://localhost/myproject/tests/harness.html
–host=”http://SL_USERNAME:SL_API_KEY@ondemand.saucelabs.com:80/wd/hub”
–cap browserName=firefox –cap platform=XP

For convenience, instead of setting the “–host” option manually, one can specify “–saucelabs-user” and “–saucelabs-key” options.

__SIESTA_DIR__/bin/webdriver http://localhost/myproject/tests/harness.html
–saucelabs-user=SL_USERNAME –saucelabs-key=SL_API_KEY
–cap browserName=firefox –cap platform=XP

Conclusion

As you can see, thanks to the excellent Sauce Labs infrastructure, launching your tests in the cloud is as easy as specifying one extra argument on the command line. The benefits of cloud testing are obvious – no need to waste time and resources setting up and maintaining your own VM farm, and additionally you can run your test suite in various browsers in parallel.

Additional Resources