Sauce Labs and BrowserStack – What Are They and Why Use Them?
This approach still work fine, but we came up with a much better one. Head over to GitHub and see our Multi-Browser-TestSuite for XLT. It will make multi browser testing a breeze. By the way, all the code is licensed under the MIT license, so absolute flexibility for you.
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.
1 |
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); |
Now set the desired version of the browser:
1 |
capabilities.setCapability("version", "19.0"); |
Set the operating system on which you want the test case to run:
1 |
capabilities.setCapability("platform", Platform.LINUX); |
Give your test case a name so that you can refer to it later:
1 |
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:
1 2 3 |
Webdriver driver = new RemoteWebDriver( new URL("http://xxx:yyy@ondemand.saucelabs.com:80/wd/hub"), capabilities); setWebDriver(driver); |
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:
1 2 3 4 5 6 7 8 9 10 |
DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("browser", "FireFox"); caps.setCapability("browser_version", "22.0"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "7"); caps.setCapability("browserstack.debug", "true"); driver = new RemoteWebDriver( new URL("http://" + USERNAME + ":" + AUTOMATE_KEY + "@hub.browserstack.com/wd/hub”, caps); setWebDriver(driver); |
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.
Great writeup, I’d also like to mention that we at TestingBot also provide a way to run your tests on our Selenium grid!