Run an Example Test on SauceLabs
Introduction
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:
https://www.testingdocs.com/saucelabs-credentials-to-run-cloud-tests/
Capabilities
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.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import java.net.URL; 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 + "@ondemand.saucelabs.com:443/wd/hub"; 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("https://www.bing.com"); driver.findElement(By.id("sb_form_q")) .sendKeys("Hello"); driver.findElement(By.id("sb_form_go")).click(); WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.titleContains("Hello")); Assert.assertEquals("Hello - Bing", driver.getTitle()); driver.quit(); } }
Running Tests in SauceLabs
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.
—
Selenium Tutorials
Selenium WebDriver Tutorials on this website can be found at:
https://www.testingdocs.com/selenium-webdriver-tutorial
For more details on the Selenium, visit the official website at: