Simple Appium Script to run on SauceLabs Server






Simple Appium Script to run on SauceLabs Server 

Create and account on Saucelabs and just replace the USERNAME and ACCESS_KEY with your credentials.

The process is clearly defined here:

https://wiki.saucelabs.com/display/DOCS/Best+Practice%3A+Use+Environment+Variables+for+Authentication+Credentials


package rough;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;

public class SaucelabsSpike2 {

public static final String USERNAME = "xxxxxx";
public static final String ACCESS_KEY = "bfd66a9c-aa3f-445d-ab75-2416aa03c44a";
public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";
public static AppiumDriver driver;

@BeforeClass
public void config() {
System.out.println("URL" + URL);

DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Samsung Galaxy S4 Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("app", "http://saucelabs.com/example_files/ContactManager.apk");
capabilities.setCapability("browserName", "");
capabilities.setCapability("deviceOrientation", "portrait");
capabilities.setCapability("appiumVersion", "1.5.3");

try {
driver = new AndroidDriver<>(new URL(URL), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Test
public void sampleTest() {

driver.findElementById("com.example.android.contactmanager:id/showInvisible").click();

driver.findElementByAccessibilityId("Add Contact").click();
driver.findElementById("com.example.android.contactmanager:id/contactNameEditText").sendKeys("Test");
 driver.findElementByAccessibilityId("Save").click();
}

@AfterClass public void tearDown()
{
driver.quit();

}

}

Comments