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 org.hamcrest.MatcherAssert.*;
24 import static org.hamcrest.Matchers.*;
25 import static org.openqa.selenium.remote.CapabilityType.*;
26
27 import java.io.*;
28 import java.net.*;
29
30 import org.openqa.selenium.*;
31 import org.openqa.selenium.remote.*;
32 import org.testng.annotations.*;
33
34 import edu.umd.cs.findbugs.annotations.*;
35 import io.appium.java_client.android.*;
36 import lombok.*;
37
38
39
40
41 public class TestingAndroidApplication {
42 private WebDriver webDriver;
43
44 @SneakyThrows
45 static AndroidDriver localApp() {
46 return new AndroidDriver(
47 new URL("http://127.0.0.1:4723/wd/hub"),
48 new DesiredCapabilities() {
49 {
50 setCapability(PLATFORM_NAME, ANDROID);
51 setCapability(DEVICE_NAME_OPTION, "DONTCARE");
52 setCapability(AUTO_WEB_VIEW_OPTION, true);
53 setCapability(APP_OPTION,
54 new File(System.getProperty("user.dir"), "app.apk")
55 .toString());
56 }
57 });
58 }
59
60 @Test
61 public void shouldRequireEmail() {
62
63 assertThat(webDriver
64 .findElements(By.xpath("//*[text()='Please enter valid email']")),
65 not(empty()));
66 }
67
68 @SuppressFBWarnings(
69 value = "UPM_UNCALLED_PRIVATE_METHOD",
70 justification = "called by testng framework")
71 @AfterClass(alwaysRun = true)
72 private void afterClassCloseWebDriver() {
73 webDriver.quit();
74 }
75
76 @SuppressFBWarnings(
77 value = "UPM_UNCALLED_PRIVATE_METHOD",
78 justification = "called by testng framework")
79 @BeforeClass
80 private void beforeClassOpenWebDriver() {
81
82
83
84 webDriver = localApp();
85 }
86 }