Return waituntil 方法是真还是假 webdriver.io

Return true or false on waituntil method webdriver.io

我正在使用 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

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

waitUntil returns 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;
}