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";

//@BeforeClass
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";
*/
//openBrowserCloud(URL);
/*
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browserName", "iPhone");
caps.setPlatform(Platform.MAC);
caps.setCapability("device", "iPhone 6S");
driver = new RemoteWebDriver(new URL(URL), caps);
*/
}

@Test
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("platformVersion","8.4");
caps.setCapability("platformName", "iOS");
caps.setCapability("browserName", "Safari");

// Flow
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
driver.get("http://www.google.com");
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='GoogleText']")).sendKeys("DXB");
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);

}

}

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 *

Test Automation
Test Automation some useful selenium hacks

Selenium Hacks- In this post I will be sharing some quick tips on selenium,Below are some of the code snippets that I mostly used when I am creating java test cases using selenium webdriver. I hope the same will help you save some time in your test script creation. These …

automation testing
Test Automation
Test Automation-Easy steps to create test-output folder Backup in TestNG automatically

Overview– TestNG is widely used and most preferred in test automation, It contains several features that are beneficial for Unit testing, regression, and Integration testing. In this article we will see out report generated by Test-NG can be copied in every run. Test-NG generate its execution report in test-output folder, …

Test Automation
IT Automation-Integration of Selenium and Sniffing tool (HttpWatch)

HTTP Watch and selenium integration- Process automation reduces the time and increases accuracy as well gives ample time to invest energy in other areas of the project. In this blog post, I will be talking about IT process automation, I will be doing an integration of sniffing tool and test …

Shares