forked from anandbagmar/AppiumJavaSample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppiumWebAndroidHelloWorldTest.java
executable file
·82 lines (68 loc) · 2.55 KB
/
AppiumWebAndroidHelloWorldTest.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
72
73
74
75
76
77
78
79
80
81
82
package com.eot.sample.android;
import com.eot.utils.DriverUtils;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.testng.ITestResult;
import org.testng.annotations.*;
import java.lang.reflect.Method;
import java.time.Duration;
import java.util.Date;
import static com.eot.sample.Hooks.*;
public class AppiumWebAndroidHelloWorldTest {
private AppiumDriver driver;
@BeforeSuite
public void beforeAll() {
startAppiumServer();
}
@AfterSuite
public void afterAll() {
stopAppiumServer();
}
@BeforeMethod
public void beforeMethod(Method method) {
DriverUtils.setChromeDriverForConnectedDevice();
driver = setupMobileWeb();
}
@AfterMethod
public void afterMethod(ITestResult result) {
if (null != driver) {
System.out.println("Close the driver");
driver.quit();
}
}
@Test()
public void appiumWebTest() throws
InterruptedException {
System.out.println("Start time: " + new Date());
driver.get("https://applitools.com/helloworld");
for (int stepNumber = 0; stepNumber < 5; stepNumber++) {
driver.findElement(By.linkText("?diff1"))
.click();
Thread.sleep(1000);
}
driver.findElement(By.tagName("button"))
.click();
System.out.println("End time: " + new Date());
}
private AppiumDriver setupMobileWeb() {
// Appium 1.x
// DesiredCapabilities capabilities = new DesiredCapabilities();
// Appium 2.x
UiAutomator2Options capabilities = new UiAutomator2Options();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability("chromedriverExecutable", System.getProperty("webdriver.chrome.driver"));
// Open browser.
AppiumDriver driver = null;
driver = new AppiumDriver(getAppiumServerUrl(), capabilities);
driver.manage()
.timeouts()
.implicitlyWait(Duration.ofSeconds(60));
return driver;
}
}