SauceLabs : Running an Example Sample Test


In this post, we will see how to run a sample test on SauceLabs. You need to have a SauceLabs account to set up and run the program. The sample program requires the SauceLabs username and access key.

To get the access key:


SauceLabs Website


Let’s write a sample test that searches the Bing home page for a keyword and asserts the title of the results page.

We will run the program on Mozilla Firefox browser version 46 by setting the DesiredCapabilities and on Windows 10 operating system.

DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("platform", "Windows 10"); caps.setCapability("version", "46.0");



Sample Test:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
public class SampleBingTest { public static final String USERNAME = "SAUCE_USERNAME_GOES_HERE"; public static final String ACCESS_KEY = "SAUCELAB_ACCESS_KEY_GOES_HERE"; public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + ""; public static void main(String[] args) throws Exception { DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("platform", "Windows 10"); caps.setCapability("version", "46.0"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); driver.get(""); driver.findElement("sb_form_q")).sendKeys("HelloWorld"); driver.findElement("sb_form_go")).click(); WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.titleContains("Hello")); Assert.assertEquals("HelloWorld - Bing", driver.getTitle()); driver.quit(); }


Running Tests in SauceLab

If you are planning to run your tests on Saucelabs, below are some Basics to follow Before Running Your Test

You need to have set up a Sauce Labs account
You should have an existing Test that you want to run on Sauce.
The website you want to test must be accessible over the Internet for Browsers to be able to reach it.
If the website or application you want to test is behind a firewall, you need to set up a secure Sauce Connect Proxy tunnel to connect to it.