Into Cloud with SauceLabs

If you don’t want to spend your time and resources developing and maintaining your own infrastructure, you can use 3rd party cloud service like BrowserStack or SauceLabs. Both companies made it easy for its customers to run automation against their on-cloud environment, and it is secure and reliable.

Of course, you will have to pay for their service, but for long run it might save you a lot money by choosing service plan that suits your need.

To run automation against BrowserStack or SauceLabs, first you need to create an account with them of course, you also need to tweak your code a little in order to run everything on cloud.

The following is a brief description of how to run your automation with Sauce Labs. Run with BrowserStack is similar.

Open an Account with Sauce Labs:

1. Go to https://saucelabs.com/, and create an account. You can start with a free trial account to get a feeling of how code run looks like there, and then choose a plan that suits your need.

2. Then login and get your ACCESS KEY in My Acccount page (The key is something like this: aeee6bed-a92e-4ff0-828b-68d0fdd9xxxx). We will need this key to access Sauce Labs server later on.

Tweak your code for cloud run

1.We need to change the way we create RemoteWebDriver to point at Sauce Labs’s URL:

private static final String USERNAME = “yourUserName”;
//The key looks like this: aeee6bed-a92e-4ff0-828b- 68d0fdd9xxxx”;
private static final String ACCESS_KEY = “yourAccessKey”;

//URL of your website under test
private static final String AUT_URL = “http://www.xxxx.xxx”;
private final String sauceLabsHubURL = “https://” + USERNAME + “:” + ACCESS_KEY + “@ondemand.saucelabs.com:443/wd/hub”;
….
DesiredCapabilities capabilities = new DesiredCapabilities();
… Here set browser name, version etc in capabilities per your need ….

driver = new RemoteWebDriver(new URL(sauceLabsHubURL),capabilities);
driver.get(AUT_URL);
……

2. Take Remote Screenshot: Make sure that you modify your code to take screenshot remotely when case fails. All you need to do is to augment your driver instance when you call your normal method for taking screenshot like this:

takeScreenshot(new Augmenter().augment(driver ), result);

This is really all you need to do! Then you can run your tests from your local machine or define a jenkins job to pull this code over and run!

Can I see the real time run screen?
A:Yes, sauce Labs provides real-time video of the node screen, where your test is running on! Everything is displayed in the dashboard of your account as following:

Figure 1: Sauce Labs Dashboard

And you can click on the session links to see the real-time video of the running screen of your chosen browser!

What about my debugging console & screenshots & reporting?
A: All these things remains the same as when you run your test on your local machine or via jenkins. I.e console & screenshots & reporting will be on your local machine if you trigger your run from your local machine, or stored on jenkins server if you run it from jenkins.