forked from anandbagmar/AppiumJavaSample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppiumNativeiOSHelloWorldTest.java
74 lines (61 loc) · 2.51 KB
/
AppiumNativeiOSHelloWorldTest.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
package com.eot.sample.ios;
import io.appium.java_client.AppiumBy;
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 static com.eot.sample.Hooks.*;
public class AppiumNativeiOSHelloWorldTest {
private static final String UDID = "D980DC00-36CC-4836-8D05-C246DC5179A1";
private static final String DEVICE_NAME = "iPhone 14 Pro";
private static final String PLATFORM_VERSION = "16.2";
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 runIOSNativeAppTest() {
driver.findElement(AppiumBy.accessibilityId("Make the number below random."))
.click();
driver.findElement(AppiumBy.accessibilityId("MakeRandomNumberCheckbox"))
.click();
driver.findElement(AppiumBy.accessibilityId("SimulateDiffsCheckbox"))
.click();
driver.findElement(By.xpath("//XCUIElementTypeStaticText[@name=\"Click me!\"]"))
.click();
}
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("app", System.getProperty("user.dir") + "/src/test/resources/sampleApps" +
"/HelloWorldiOS.app");
// dc.setCapability("app", System.getProperty("user.dir") + "/src/test/resources/sampleApps/eyes-ios-hello-world.zip");
return new AppiumDriver(getAppiumServerUrl(), dc);
}
}