Browser Automation usig Saucelabs

Sun, Nov 10, 2019

Read in 2 minutes

Let’s see how to open desired browser using Java + Saucelabs + Selenium

Saucelabs is a cloud server where you can access any browser , any version , any resolution and in any Operating system.

RemoteWebDriver remoteDriver = null;

DesiredCapabilities remoteDriver_capabilities;; remoteDriver_capabilities.setCapability(“version”, “81.0”); remoteDriver_capabilities.setCapability(“platform”, “Windows 10”);

sauceUrl = String.format(“”, “<SAUCELABS USERNAME>” , “<SAUCELABS ACCESS KEY>”);

remoteDriver = new RemoteWebDriver(new URL(sauceUrl), remoteDriver_capabilities);


Now you can login to saucelabs and view the test running and desired URL is opened in desired browser

Other capabilities in SauceLabs – You can accept SSL certificate error as below,


By default max duration for a single session is 180 Sec. Can be increased as below,

remoteDriver_capabilities.setCapability(“maxDuration”, 10800);

Browser latest version can be access as below,

remoteDriver_capabilities.setCapability(“version”, “latest”);

Full Code Open in chrome browser , Windows 10 and in desired resolution

package demo;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class demo
	public static void main( String args[] ) throws URISyntaxException, InterruptedException
		RemoteWebDriver remoteDriver = null;
		 * Declare remote driver desired capabilities
		DesiredCapabilities remoteDriver_capabilities;; // Browser
		remoteDriver_capabilities.setCapability("version", "81.0"); // Browser Version
		remoteDriver_capabilities.setCapability("platform", "Windows 10"); //OS version
		remoteDriver_capabilities.setCapability("screenResolution", "1280x800"); //set the browser resolution
		String sauceUrl = String.format("", "<SAUCELABS USERNAME>","<SAUCELABS ACCESS KEY>");
		try {
			remoteDriver = new RemoteWebDriver(new URL(sauceUrl), remoteDriver_capabilities);
		} catch (MalformedURLException e) {