没有任何一种webdriverio方法可以等到使用Appium和WebDriverIO(JavaScript)显示元素

时间:2020-01-28 13:27:45

标签: javascript webdriver appium webdriver-io

我正在尝试使用JavaScript与webdriverio(使用appium服务器)一起使用原生Android应用程序的测试用例。

我的测试用例要求我登录应用程序,并且在登录后(需要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 https://webdriver.io/docs/api/element/waitForClickable.html

的WebDriverIO文档

我的代码如下:

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
    })
})

登录测试成功完成,但是在按下LOG-IN按钮之后,我想让我的测试套件“休眠”直到下一页加载为止,要实现这一点,我试图等到这个特定的Profile按钮(元素)可用,但似乎无法等待。

有人可以建议我在这种情况下该怎么办,我该如何等待?

1 个答案:

答案 0 :(得分:1)

从v4-> v5迁移时,WebDriverIO更改了其中一些功能的名称,.waitForDisplayed()是其中之一,as seen in the changelogs

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

很少有一些函数会稍微更改名称,因此值得一看-此外,v4 Docs仍然存在,但搜索起来有点困难-Here is the entry for .waitForVisible()

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

.waitForDisplayed(5000, true)