How to execute appium scripts in could (Saucelabs)
Explanation Coming Soon ... ... ...
----------------------------------------
Sample Code:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import java.io.File;
import java.io.InterruptedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
public class SouceLabTest {
AndroidDriver driver;
@Test
public void test() throws MalformedURLException, InterruptedIOException, InterruptedException {
DesiredCapabilities caps = DesiredCapabilities.android();
// Soucelab capabilites for Android
caps.setCapability("appiumVersion", "1.6.4");
caps.setCapability("deviceName", "Android Emulator");
caps.setCapability("deviceOrientation", "portrait");
caps.setCapability("browserName", "");
caps.setCapability("platformVersion", "4.4");
caps.setCapability("platformName", "Android");
caps.setCapability("app", "sauce-storage:selendroid-test-app-0.17.0.apk");
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://spradhan40:93c3c6d0-9dfa-4039-b723-749a128ceb94@ondemand.saucelabs.com:80/wd/hub"), caps);
// Souclab capabilites for iOS DesiredCapabilities
/*DesiredCapabilities dc = DesiredCapabilities.iphone();
dc.setCapability("platformName", "iOS");
dc.setCapability("platformVersion", "7.1");
dc.setCapability("appiumVersion", "1.6.4");
dc.setCapability("deviceName", "iPhone Simulator");
dc.setCapability("browserName", "");
dc.setCapability("app", "sauce-storage:UICatalog.app.zip");
IOSDriver driver2 = new IOSDriver(new URL("http://spradhan40:93c3c6d0-9dfa-4039-b723-749a128ceb94@ondemand.saucelabs.com:80/wd/hub"), caps);*/
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
// driver.get("http://www.rediff.com/");
driver.findElement(By.id("io.selendroid.testapp:id/buttonStartWebview")).click();
Thread.sleep(3000);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")) {
driver.context(contextName);
}
}
}
}
Comments
Post a Comment