3 Easy steps for Running selenium scripts in Sauce Labs

Test Automation

Hello Readers,

Its been a long time publishing any post, I have done a small execution of selenium script in a remotely placed device on saucelabs.

Below piece of code will help you in doing the same.

There are 3 simple steps to connect and run your automation script in remote device.

Step-1 Set Connection- Pass credentials through java code
Step-2 Set Capability- Set capability, settings for which you want to run on which availabel device which is placed remotely.
Step-3 Execute your script

package testcases.SauseLabs;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import webdriver.Libs;

public class SL_MobileTestSuite extends Libs {
//public static WebDriver driver;
//String URL = setCloudSettings();
public static final String USERNAME = "PrashantChaudhary";
public static final String ACCESS_KEY = "e7439e4d-1fe5-4b77-a620-e451e1a83ee8";
public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:80/wd/hub";

public void beforeClass() throws MalformedURLException {

final String USERNAME = "PrashantChaudhary";
final String AUTOMATE_KEY = "6nbDQmCQsm5aGfEgDNs3";
final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "iPhone");
caps.setCapability("device", "iPhone 6S");
driver = new RemoteWebDriver(new URL(URL), caps);

public void Scenario1() throws MalformedURLException

// Proxy Settings HTTP & HTTPS
System.getProperties().put("http.proxyHost", "XYX");
System.getProperties().put("http.proxyPort", "80");
System.getProperties().put("https.proxyHost", "XYZ");
System.getProperties().put("https.proxyPort", "80");

// Set capabilities - Device & browser
DesiredCapabilities caps = DesiredCapabilities.iphone();
caps.setCapability("appiumVersion", "1.5.1");
caps.setCapability("deviceName","iPhone 6");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "Safari");

// Flow
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);



Please use above code snippet and let me know if in case you need more help .

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Selenium Basic
Step by step selenium – step 3, what is findelement method

Abstract- So far, we have learned how to launch a web browser, entering values in a text box and clicking button. In this post, we will learn about findelement method. Test automation is all about get and set, which means get from web and set into web. Talking more specifically- …

Test Automation
What is ITestListner interface and its Use in Selenium

There are several interfaces available in TestNG that allow you to modify TestNG’s behavior or to give test scripts additional strength. These interfaces are broadly called “TestNG Listeners”. Here are a few listeners which are commonly used: 1- IAnnotationTransformer 2- IAnnotationTransformer2 3- IHookable 4- IInvokedMethodListener 5- IMethodInterceptor 6- IReporter 7- …

Test Automation
How to Capture Screenshot in Selenium Webdriver-3 different ways

Abstract– Capturing screenshot is an essential feature of a test automation framework, They help in defect analyses once after test execution is over. In this blog post we will see how to capture screenshot, there are different ways to capture screenshots. Which includes- 1- Capture full Page 2- Capturng full …