1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.testing.example.scenarios.tutorial4;
18
19 import static io.appium.java_client.remote.MobilePlatform.*;
20 import static io.appium.java_client.remote.options.SupportsAppOption.*;
21 import static io.appium.java_client.remote.options.SupportsAutoWebViewOption.*;
22 import static io.appium.java_client.remote.options.SupportsDeviceNameOption.*;
23 import static io.appium.java_client.remote.options.SupportsPlatformVersionOption.*;
24 import static org.hamcrest.MatcherAssert.*;
25 import static org.hamcrest.Matchers.*;
26 import static org.openqa.selenium.remote.CapabilityType.*;
27
28 import java.net.*;
29 import java.time.*;
30 import java.time.format.*;
31
32 import org.openqa.selenium.*;
33 import org.openqa.selenium.remote.*;
34 import org.testng.annotations.*;
35
36 import edu.umd.cs.findbugs.annotations.*;
37 import io.appium.java_client.android.*;
38 import lombok.*;
39
40
41
42
43 public class TestingAndroidOnSauceLabs {
44
45 private WebDriver webDriver;
46
47 @java.lang.SuppressWarnings("serial")
48 @SneakyThrows
49 static AndroidDriver saucelabsApp(
50 final String name) {
51 return new AndroidDriver(new URL(
52
53
54 "https://TBD:TBD@ondemand.saucelabs.com:443/wd/hub"),
55 new DesiredCapabilities() {
56 {
57 setCapability(PLATFORM_NAME, ANDROID);
58 setCapability(PLATFORM_VERSION_OPTION, "8");
59 setCapability(DEVICE_NAME_OPTION,
60 "Samsung Galaxy S9 Plus WQHD GoogleAPI Emulator");
61 setCapability(AUTO_WEB_VIEW_OPTION, true);
62 setCapability(APP_OPTION, "sauce-storage:app.apk");
63 setCapability("name", name);
64 setCapability("build", "local-"
65 + DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
66 .withZone(ZoneOffset.UTC)
67 .format(Instant.now()));
68 }
69 });
70 }
71
72 @Test
73 public void shouldRequireEmail() {
74 assertThat(webDriver
75 .findElements(By.xpath("//*[text()='Please enter valid email']")),
76 not(empty()));
77 }
78
79 @SuppressFBWarnings(
80 value = "UPM_UNCALLED_PRIVATE_METHOD",
81 justification = "called by testng framework")
82 @AfterClass(alwaysRun = true)
83 private void afterClassCloseWebDriver() {
84 webDriver.quit();
85 }
86
87 @SuppressFBWarnings(
88 value = "UPM_UNCALLED_PRIVATE_METHOD",
89 justification = "called by testng framework")
90 @BeforeClass
91 @SneakyThrows
92 private void beforeClassOpenWebDriver() {
93
94
95
96
97 webDriver = saucelabsApp(getClass().getSimpleName());
98 webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
99 }
100 }