【问题标题】:Scroll to an element with Appium, wd and React Native使用 Appium、wd 和 React Native 滚动到一个元素
【发布时间】:2021-10-26 12:35:47
【问题描述】:

我正在尝试向下滚动到我的 react 本机集成测试中的一个按钮。我正在使用 appium 版本 1.21.0、UiAutomator2 和 wd 在 Android 模拟器上运行测试,但找不到滚动测试的方法。有没有办法用js、wd和appium实现滚动?

【问题讨论】:

    标签: android react-native webdriver appium


    【解决方案1】:

    这是我们用来进行滚动的一些代码。 iOS 和 Android 的技术不同:

    const element = driver.waitForElementById(...);
    
    if (platformIsIOS()) {
      await driver.execute("mobile: scroll", {
        element,
        direction: distY <= 0 ? "down" : "up",
      });
    
    } else {
      let action = new wd.TouchAction(driver);
      action.press({ el: element, x: fromX, y: fromY });
      action.wait(Timeouts.Default);
      action.moveTo({ el: elementName, x: fromX + distX, y: fromY + distY });
      action.release();
      for (let i = 0; i < repeatTimes; i++) {
        await action.perform();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-19
      • 2019-10-14
      • 1970-01-01
      • 2019-12-18
      • 2017-11-26
      • 2023-03-08
      • 2016-07-19
      • 2020-10-01
      • 2011-10-04
      相关资源
      最近更新 更多