forked from anandbagmar/AppiumJavaSample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppiumWebiOSHelloWorldTest.java
78 lines (62 loc) · 2.39 KB
/
AppiumWebiOSHelloWorldTest.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
package com.eot.sample.ios;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.options.XCUITestOptions;
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.util.Date;
import static com.eot.sample.Hooks.*;
public class AppiumWebiOSHelloWorldTest {
private static final String UDID = "F2D71DA6-ABD3-4311-A694-349FD64A5E7D";
private static final String DEVICE_NAME = "iPhone 12 Pro Max";
private static final String PLATFORM_VERSION = "14.5";
private AppiumDriver driver;
@BeforeSuite
public void beforeAll() {
startAppiumServer();
}
@AfterSuite
public void afterAll() {
stopAppiumServer();
}
@BeforeMethod
public void beforeMethod(Method method) {
driver = createAppiumDriver();
}
@AfterMethod
public void afterMethod(ITestResult result) {
if (null != driver) {
System.out.println("Close the driver");
driver.quit();
}
}
@Test
public void runIOSWebTest() throws InterruptedException {
System.out.println("Start time: " + new Date());
Thread.sleep(3000);
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();
driver.quit();
System.out.println("End time: " + new Date());
}
private AppiumDriver createAppiumDriver() {
// Appium 1.x
// DesiredCapabilities dc = new DesiredCapabilities();
// Appium 2.x
XCUITestOptions dc = new XCUITestOptions();
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION);
dc.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME);
dc.setCapability(MobileCapabilityType.UDID, UDID);
dc.setCapability(MobileCapabilityType.BROWSER_NAME, "safari");
dc.setCapability(MobileCapabilityType.APP, "io.appium.SafariLauncher");
return new AppiumDriver(getAppiumServerUrl(), dc);
}
}