我正在尝试使用iOS模拟器上的Appium 1.11.1进行一些UITest,并且Swipe无法正常工作
驱动程序连接看起来不错。.我可以测试driver.reloadApp()并正常工作
我已经尝试了一些有关TouchActions的堆栈溢出示例
public static void swipeHorizontal(MobileDriver driver, double startPercentage, double finalPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int height = (int) (size.height/2);
int startPoint = (int) (size.getWidth() * startPercentage);
int endPoint = (int) (size.getWidth() * finalPercentage);
new TouchAction(driver).press(new PointOption().point(height, startPoint)).waitAction(new WaitOptions().waitOptions(Duration.ofMillis(duration))).moveTo(new PointOption().point(height, endPoint)).release().perform();
}
@Test.....{
swipeHorizontal(driver, 0.80, 0.20, 5);
}
并且测试通过了,但是屏幕上没有任何反应
我也https://stackoverflow.com/a/50388361/7406696尝试过此解决方案,但它不能与我的模拟器一起使用
我的pom.xml是这个
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
答案 0 :(得分:0)
最后的工作是删除waitOptions并将其从press()更改为longPress()
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height/2);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).longPress(new PointOption().point(startPoint, anchor)).moveTo(new PointOption().point(endPoint, anchor)).release().perform();
}
@Test..... {
swipeHorizontal(driver, 0.80, 0.20);
}