【问题标题】:Is it ok to use TouchAction.press & waitaction which are deprecated, in Appium是否可以在 Appium 中使用已弃用的 TouchAction.press 和 waitaction
【发布时间】:2018-08-16 19:54:28
【问题描述】:

目前我正在为一个 ios 离子应用程序编写一个 Appium 脚本,并且我使用以下方法来实现滑动功能。

public void swipeHorizontal(AppiumDriver<MobileElement> driver, double startPercentage, double finalPercentage, int duration) throws Exception {
    Dimension size = driver.manage().window().getSize();
    int width = (int) (size.width/2);
    int startPoint = (int) (size.getHeight()*startPercentage);
    int endpoint = (int) (size.getHeight()*finalPercentage);
    new TouchAction(driver).press(width,startPoint).waitAction(Duration.ofSeconds(0)).moveTo(width,endpoint).release().perform();
   }

在上述方法中,单词 press、waitAction 和 moveto 被切断,消息“press(int,int)”已弃用。与 waitAction 和 moveto 类似。可以使用这种已弃用的方法还是我做错了什么?

【问题讨论】:

    标签: webview automation automated-tests appium appium-ios


    【解决方案1】:

    每当您看到某项“已弃用”时,这意味着虽然它在技术上仍受支持,但仅受支持以便现有(旧版)应用程序继续运行,并且一些新的、据称更好的东西已取代它,并且您应该改用新方法。

    现在 Appium 中有一个 swipe 方法,它让事情变得简单了很多。这是我使用滑动的代码:

    /**
     * This method performs a swipe on an Android element
     * @author Bill Hileman
     * @param element - an Android element, i.e. an EditView, TextView, etc.
     * @param locator - a verbal description of the element for logging purposes
     * @param direction - a value of type SwipeElementDirection
     * @param duration - time in milliseconds for the swipe to complete
     */
    public void swipe(AndroidElement element, String locator, SwipeElementDirection direction, int duration) {
    
        try {
            element.swipe(direction, duration);
        } catch (NullPointerException | NoSuchElementException e) {
            System.err.println("Unable to locate element '" + locator + "'");
            fail();
        } catch (Exception e) {
            System.err.println("Unable to swipe " + direction.toString() + " element '" + locator + "'");
            e.printStackTrace();
            fail();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-16
      • 2018-07-19
      • 1970-01-01
      • 2020-01-14
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多