Write First Selenium-Cloud Test with Sauce Labs

  1. Go to https://saucelabs.com/
  2. Click on Try it for free.
  3. Click on Sign up with Email
  4. Provide valid Email address, Username and Password
  5. It shows initial Data center is from Australia. Don’t worry you can change it later
  6. Click on Sign Up
  1. Click on Account > User Settings
User Settings
https://username:accessKey@ondemand.dataCenter.saucelabs.com:80/wd/hub
Sauce Labs capability language support
Different Selenium Versions for Web Executions
Different Operating System for Web & Mobile Testing
Cross Browser Support
Browser Version Support
Resolution Support
Appium Version support for Select Device
public static final String USERNAME = "user_name";
public static final String ACCESS_KEY = "access_key";
https://username:accessKey@ondemand.dataCenter.saucelabs.com:443/wd/hub
public static final String Exe_URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.us-west-1.saucelabs.com:80/wd/hub";
EdgeOptions browserOptions = new EdgeOptions();
browserOptions.setCapability("platformName", "Windows 10");
browserOptions.setCapability("browserVersion", "91.0");
WebDriver driver = new ChromeDriver();
OR
WebDriver driver = new FirefoxDriver();
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) {
this(new HttpCommandExecutor(remoteAddress), capabilities);
}
driver = new RemoteWebDriver(new URL(Exe_URL), browserOptions);
@Test
public void testGoogle(){

driver.get("https://www.google.com/");
driver.findElement(By.name("q"));
Assert.assertEquals(driver.getTitle(),"Google");

}
@AfterTest
public void tearDown(ITestResult result) throws Exception{
driver.quit();
}
public class Web_Execution_on_Sauce{public static final String USERNAME = "user_name";public static final String ACCESS_KEY = "access_key";public static final String Exe_URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.us-west-1.saucelabs.com:80/wd/hub";WebDriver driver;    @BeforeTest
public void sauceCapabilities() throws MalformedURLException {
EdgeOptions browserOptions = new EdgeOptions();
browserOptions.setCapability("platformName", "Windows 10");
browserOptions.setCapability("browserVersion", "91.0");
driver = new RemoteWebDriver(new URL(Exe_URL), browserOptions);
}
@Test
public void testGoogle(){
driver.get("https://www.google.com/");
driver.findElement(By.name("q"));
Assert.assertEquals(driver.getTitle(),"Google");

}
@AfterTest
public void tearDown(){
driver.quit();
}
Job Completed
public void tearDown(ITestResult result) throws Exception{
String status = result.isSuccess() ? "passed" : "failed";
((JavascriptExecutor) driver).executeScript("sauce:job-result=" + status);
driver.quit();
}
org.testng.TestNGException: 
Can inject only one of <ITestContext, XmlTest> into a @AfterTest annotated tearDown.
PC: TestNG_Doc
public class Web_Execution_on_Sauce{public static final String USERNAME = "user_name";public static final String ACCESS_KEY = "access_key";public static final String Exe_URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.us-west-1.saucelabs.com:80/wd/hub";WebDriver driver;@BeforeMethod
public void sauceCapabilities() throws MalformedURLException {
EdgeOptions browserOptions = new EdgeOptions();
browserOptions.setCapability("platformName", "Windows 10");
browserOptions.setCapability("browserVersion", "91.0");
driver = new RemoteWebDriver(new URL(Exe_URL), browserOptions);
}
@Test
public void testGoogle(){
driver.get("https://www.google.com/");
driver.findElement(By.name("q"));
Assert.assertEquals(driver.getTitle(),"Google");

}
@AfterMethod
public void tearDown(ITestResult result) throws Exception{
String status = result.isSuccess() ? "passed" : "failed";
((JavascriptExecutor) driver).executeScript("sauce:job-result=" + status);
driver.quit();
}
}

--

--

--

I am having an 6+ years of experience in software testing.Working with Web, Mobile and API technologies.Visit my GIT https://github.com/monilj

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Prod++[3]: Leaner Search Using DuckDuckGo !Bangs

How does HBase scale?

How to Build a Job Search Website Like Indeed

How You, The New Data Professional, Can Handle Your First Code Review

Code on a dark computer screen.

Where to Go to Find Awesome Developers for Your Startup

A Different Lens to Monitor your Serverless Architecture: Operations Search!

Specialization Clarification 1.0— Software Engineering

Back-end development with Spring boot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Monil Joshi

Monil Joshi

I am having an 6+ years of experience in software testing.Working with Web, Mobile and API technologies.Visit my GIT https://github.com/monilj

More from Medium

Different Techniques Of Debugging Selenium Based Test Scripts

How does Selenium Page Factory work with Cucumber?

How To Handle Cookies in Selenium WebDriver

Face and emotion detection via Google Cloud’s vision api