使用 Appium 和 WebDriverIO (JavaScript)

Non of the webdriverio methods work to wait until an element is shown using Appium & WebDriverIO (JavaScript)

我正在尝试使用 webdriverio(使用 appium 服务器)为本机 android 应用编写 JavaScript 中使用的测试用例。

我的测试用例要求我登录应用程序,登录后(需要 3-4 秒)我应该单击一个按钮(元素)。我尝试了所有 WebDriverIO API,如 waitForDisplayed、isDisplayed(),但没有一个有效,大多数时候错误消息是:

  TypeError: client.element(...).waitForDisplayed is not a function
      at Context.<anonymous> (test-auto-obi-copy.js:142:14)
      at processImmediate (internal/timers.js:439:21)
      at process.topLevelDomainCallback (domain.js:130:23)

这是 waitForDisplayed 的 WebDriverIO 文档 https://webdriver.io/docs/api/element/waitForClickable.html

我的代码如下所示:

it("should press the profile button", function () {
    return client
    .element('android=new UiSelector().resourceId("com.example.dev:id/nav_graph_profile")')
    .waitForDisplayed(undefined, true)
    .click('android=new UiSelector().resourceId("com.example.dev:id/nav_graph_profile")')
    .then( function() {
        //whatever
    })
})

登录测试成功完成,但在按下登录按钮后,我想让我的测试套件 "sleep" 直到下一页加载,为了实现这一点,我试图等到这个特定的配置文件按钮(元素)可用,但似乎无法等待。

任何人都可以建议我在这种情况下该怎么办,我怎么能等?

WebDriverIO 在从 v4 -> v5 移动时更改了一些函数的名称 .waitForDisplayed() 就是其中之一,as seen in the changelogs

  • WebdriverIO v4 -> .waitForVisible()
  • WebdriverIO v5 -> .waitForDisplayed()

有相当多的函数稍微更改了名称,因此值得一看 - 此外,v4 的文档仍然存在,但搜索起来有点困难 - Here is the entry for .waitForVisible()

此外,通过将 undefined 作为第一个参数传递,您的延迟将只等待默认的 500ms。你可能会想要这样的东西

.waitForDisplayed(5000, true)