Wednesday, 12. March 2014 18:13
Sauce Labs and BrowserStack – What Are They and Why Use Them?
Sauce Labs and BrowserStack allow you to run automated test cases on different browsers and operating systems. Both provide more than 200 mobile and desktop browsers on different operating systems. The benefit? You can focus on coding instead of having to maintain different devices. You can easily run your test cases written on iOS on an Internet Explorer without actually buying a Windows device; and last not least, you don’t need to worry about drivers or maintenance.
By the way, Internet Explorer even seems to run faster at Sauce Labs than on a desktop machine. Also note that Sauce Labs supports Maven builds.
What You Need
Not much, really. Only a Sauce Lab or BrowserStack account, a Java IDE (e.g., Eclipse), and XLT 4.3.2.
How to Do it
First, import your XLT test suite into the IDE (Eclipse). Then import all .jar files from the XLT lib directory into your project. In the XLT Script Developer options menu, check “Generate JUnit wrapper class for test cases” and save your test cases.
Add the statements below to the exported Java wrapper. Here you can choose your browser (Android, Safari, Firefox, Chrome, Internet Explorer). Place this code in the constructor.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
Now set the desired version of the browser:
Set the operating system on which you want the test case to run:
Give your test case a name so that you can refer to it later:
capabilities.setCapability("name", "XLT Firefox Test");
Now you can set up a new WebDriver. Replace “xxx” by your user name and “yyy” by your access key for Sauce Labs:
Webdriver driver = new RemoteWebDriver(
new URL("http://xxx:email@example.com:80/wd/hub"), capabilities);
With this piece of code you should be able to run your test cases on the Sauce Lab servers. This also works to for manually written classes. Just use the same WebDriver settings.
For BrowserStack, you can use the following commands:
DesiredCapabilities caps = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(
new URL("http://" + USERNAME + ":" +
AUTOMATE_KEY + "@hub.browserstack.com/wd/hub”, caps);
Some Final Notes
Selenium works best with Chrome and Firefox. Other browsers, like Internet Explorer or Safari, may fail on test cases that, in fact, do successfully run in Chrome or Firefox. Some websites have a different layout for mobile than for desktop. So you probably can’t use your default tests. If you want to write tests for mobile devices with XLT Script Developer, install user agent changer and change your user agent to iPhone 3.
Sauce Labs provides a detailed tutorial which describes all functions of the service, like parallel testing and other cool stuff. We definitely recommend you read it in case you have any questions.