Sauce Labs

 

Configure Sauce labs with your java project

Sauce Labs is a cloud automation tool where we run 100s and 1000s of automated test cases across different platforms, browsers and versions.

I will show here how to configure sauce labs with your java project.

Steps to configure:

Prerequisites:

  • You have a Sauce Labs account.
  • You have fair knowledge about Java, TestNg and Selenium.
  1. Create a Java Class-> For eg. JavaSauceSetup
  2. Grab the sauce user name, sauce key from your account and keep it handy.
  3. In the @BeforeClass method, define the DesiredCapabilities and the instantiation of RemoteWebDriver to run our tests on Sauce Labs.
  4. See the below code snippet:
public class JavaSauceSetUp {

    final static String USERNAME = "xyz";
    final static String ACCESS_KEY = "xyz-dddd-xkuddd";
    final String URL =
        "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub";

    WebDriver driver;
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

    @BeforeClass(alwaysRun = true)
    public void beforeClass() throws MalformedURLException {
        desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("browserName", "chrome");
        desiredCapabilities.setCapability("platform", "macOS 10.13");
        desiredCapabilities.setCapability("version", "70");
        desiredCapabilities = DesiredCapabilities.chrome();
        driver = new RemoteWebDriver(new URL(URL), desiredCapabilities);
        driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);

    }
    @Test
    public void sauceTest1() {
        driver.get("https://twitter.com/i/flow/signup");
        driver.findElement(By.xpath("//input[@name=\"name\"]")).sendKeys("sdeting");
    }
}

Login to sauce labs to see live test execution or playback

SAUCE.png