forked from saucelabs-training/demo-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AndroidNativeAppTest.java
71 lines (62 loc) · 2.7 KB
/
AndroidNativeAppTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.realdevice.unifiedplatform;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.MalformedURLException;
import java.net.URL;
import static org.junit.Assert.assertTrue;
public class AndroidNativeAppTest {
@Rule
public TestName name = new TestName() {
public String getMethodName() {
return String.format("%s", super.getMethodName());
}
};
//This rule allows us to set test status with Junit
@Rule
public SauceTestWatcher resultReportingTestWatcher = new SauceTestWatcher();
public AppiumDriver<MobileElement> driver;
public AppiumDriver<MobileElement> getDriver() {
return driver;
}
@Before
public void setUp() throws MalformedURLException {
MutableCapabilities capabilities = new MutableCapabilities();
/*
* Pick your device
* */
//Not specifying platformVersion or the exact device is the most likely to
//find a device in the cloud
capabilities.setCapability("platformName", "android");
capabilities.setCapability("deviceName", "Google Pixel.*");
capabilities.setCapability("idleTimeout", "90");
capabilities.setCapability("noReset", "true");
capabilities.setCapability("newCommandTimeout", "90");
capabilities.setCapability("appWaitActivity", "com.swaglabsmobileapp.MainActivity");
capabilities.setCapability("name", name.getMethodName());
capabilities.setCapability("app",
"https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk");
driver = new AndroidDriver<>(
new URL("https://" + System.getenv("SAUCE_USERNAME") + ":" +
System.getenv("SAUCE_ACCESS_KEY") +
"@ondemand.us-west-1.saucelabs.com/wd/hub"),
capabilities);
//Setting the driver so that we can report results
resultReportingTestWatcher.setDriver(driver);
}
@Test
public void shouldOpenApp() {
WebDriverWait wait = new WebDriverWait(getDriver(), 10000);
WebElement loginField = wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("test-Username")));
assertTrue(loginField.isDisplayed());
}
}