带有新 Appium-java TouchActions 的 ClassCastException [英] ClassCastException with new Appium-java TouchActions

查看:37
本文介绍了带有新 Appium-java TouchActions 的 ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用新的 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

这篇关于带有新 Appium-java TouchActions 的 ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆