【问题标题】:Return true or false on waituntil method webdriver.io在 waituntil 方法 webdriver.io 上返回 true 或 false
【发布时间】:2020-03-20 01:19:33
【问题描述】:

我正在使用 webdriver.io v5 编写自动化框架。我想从以下方法获得布尔响应。

waitAndCheckForContactToBePresent(contactName) {
        return browser.waitUntil((value) => {
            return this.checkIfContactExists(contactName).firstName === contactName
        }, 240000, 'Contact not found', 60000);
}

目前测试失败并出现以下错误

Contact not found
[chrome  mac os x #0-0] Error: Contact not found

我想断言方法响应。如何获得布尔响应。

【问题讨论】:

    标签: javascript node.js selenium-webdriver webdriver webdriver-io


    【解决方案1】:

    waitUntil 成功时返回 true。但是当它失败时,它会抛出一个错误并打印您提供的消息。但是你可以通过捕获失败时抛出的错误来实现你正在寻找的东西。请检查以下是否适合您。

    waitAndCheckForContactToBePresent(contactName){
      let status;
      try {
        status = browser.waitUntil((value) => {
          return this.checkIfContactExists(contactName).firstName === contactName
        }, 240000, 'Contact not found', 60000);
      }
      catch (error) {
        status = false;
      };
      return status;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 2017-09-16
      • 2021-05-17
      • 1970-01-01
      • 2019-12-04
      相关资源
      最近更新 更多