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 .