gpt4 book ai didi

appium - 具有新Appium-java TouchAction的ClassCastException

转载 作者:行者123 更新时间:2023-12-04 08:31:56 25 4
gpt4 key购买 nike

我在使用新的TouchActions类时遇到了错误。

  • 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 cannot be cast to org.openqa.selenium.interactions.HasTouchScreen



    鉴于以下旧版本都可以正常工作:
    TouchAction touchAction = new TouchAction(appiumDriver);

    最佳答案

    使用W3C Actions API执行手势。

    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

    可在以下位置找到文档: https://appiumpro.com/editions/29

    关于appium - 具有新Appium-java TouchAction的ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48458726/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com