具有新Appium-java TouchAction的ClassCastException [英] ClassCastException with new Appium-java TouchActions
问题描述
我在使用新的TouchActions类时遇到了错误.
I am getting below error with new TouchActions class.
- JDK版本:1.8
- Appium:1.7.2
- appium.java-client.version:6.0.0-BETA2
- selenium.java.version:3.8.1
TouchActions actions = new TouchActions(appiumDriver);
运行时错误:
java.lang.ClassCastException:io.appium.java_client.ios.IOSDriver无法转换为org.openqa.selenium.interactions.HasTouchScreen
java.lang.ClassCastException: io.appium.java_client.ios.IOSDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
鉴于此,以下旧版本都可以正常工作:
Whereas, old below works all fine:
TouchAction touchAction = new TouchAction(appiumDriver);
推荐答案
使用W3C Actions API执行手势.
Use W3C Actions API to perform gestures.
public void horizontalSwipingTest() throws Exception {
login();
driver.findElementByAccessibilityId("slider1").click();
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("slider")));
MobileElement slider = driver.findElementByAccessibilityId("slider");
Point source = slider.getLocation();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0),
PointerInput.Origin.viewport(), source.x, source.y));
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.MIDDLE.asArg()));
dragNDrop.addAction(new Pause(finger, Duration.ofMillis(600)));
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(600),
PointerInput.Origin.viewport(),
source.x + 400, source.y));
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.MIDDLE.asArg()));
driver.perform(Arrays.asList(dragNDrop));
}
public void verticalSwipeTest() throws InterruptedException {
login();
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("verticalSwipe")));
driver.findElementByAccessibilityId("verticalSwipe").click();
wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("listview")));
verticalSwipe("listview");
}
private void verticalSwipe(String locator) throws InterruptedException {
Thread.sleep(3000);
MobileElement slider = driver.findElementByAccessibilityId(locator);
Point source = slider.getCenter();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0),
PointerInput.Origin.viewport(),
source.x / 2, source.y + 400));
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.MIDDLE.asArg()));
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(600),
PointerInput.Origin.viewport(), source.getX() / 2, source.y / 2));
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.MIDDLE.asArg()));
driver.perform(Arrays.asList(dragNDrop));
}
其他手势的示例可以在这里找到: https://github.com/saikrishna321/VodQaAdvancedAppium/blob/master/src/test/java/com/appium/gesture/GestureTest.java
Examples of other gestures can be found here: https://github.com/saikrishna321/VodQaAdvancedAppium/blob/master/src/test/java/com/appium/gesture/GestureTest.java
文档可从以下网站获取: https://appiumpro.com/editions/29
Documentation is available at: https://appiumpro.com/editions/29
这篇关于具有新Appium-java TouchAction的ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!