Javascript Selenium似乎忽略了驱动程序中的超时时间和超时消息。wait()

Javascript Selenium似乎忽略了驱动程序中的超时时间和超时消息。wait(),javascript,selenium,asynchronous,selenium-webdriver,cucumber,Javascript,Selenium,Asynchronous,Selenium Webdriver,Cucumber,我在获取自定义错误消息以使用selenium中的driver.wait()时遇到问题。定义为driver.wait(条件、超时、消息)where 条件类似于until.elementLocated(By.css('.myClass')) 超时时间以毫秒为单位 消息是“等待超时时使用的可选消息。” 更多信息请参见this.wait() 据我所知,api的要点是,如果超时时间到期而条件不为true,则可以传递超时时间和要使用的消息 考虑到这一点,我定义了一个函数locateelement Wit

我在获取自定义错误消息以使用selenium中的
driver.wait()
时遇到问题。定义为
driver.wait(条件、超时、消息)
where

  • 条件类似于
    until.elementLocated(By.css('.myClass'))
  • 超时时间以毫秒为单位
  • 消息是“等待超时时使用的可选消息。”
更多信息请参见
this.wait()

据我所知,api的要点是,如果超时时间到期而条件不为true,则可以传递超时时间和要使用的消息

考虑到这一点,我定义了一个函数
locateelement With timeout
,它需要

  • 司机
  • 定位器(类似于.css(“.myClass”))
  • 超时值(类似于
    5000
  • 超时消息(类似于“我的超时消息”)
我还定义了一个函数
typeInWithTimeout

async function typeInWithTimeout(driver, by, timeout, timeoutMessage, textToType) {
  const element = await locateElementWithTimeout(driver, by, timeout,
    `Unable to locate element for typing text - ${timeoutMessage}`);

  // bridge is needed for anything apart from firefox
  const actions = driver.actions({ bridge: true });
  await actions.click(element).sendKeys(textToType).perform();
}

await typeInWithTimeout(driver, By.id("login_box"), 5000, 'Unable to locate login box', "myUsername");
在前面的代码中(之前执行约1秒),我调用了以下函数来定义超时:

await driver.manage().setTimeouts({
  implicit: 50 * 1000,
  pageLoad: 50 * 1000,
  script: 50 * 1000,
});

现在来谈谈我的问题。我通过尝试定位一个不存在的元素来测试失败条件,期望它在我定义的
消息中抛出一个错误。我的问题是,selenium没有等待我在函数调用中请求的5秒,而是等待整整50秒,然后失败并出现
错误:函数超时,请确保承诺在50000毫秒内解决。为什么它没有在我请求的5秒内失败?

因为隐式等待。。。不要设置它。@pcalkins那么在尝试这些调用之前我应该将它设置为0吗?答案是肯定的。是-在尝试调用之前,我应该将隐式等待设置为0。事实上,甚至不要在测试中刻意等待。。由于某些原因,隐式等待优先于显式等待。隐式等待是全局性的,不应与显式等待混合。您可能可以跳过整个驱动程序。manage()。此处的SetTimeout部分。驱动程序对页面加载和脚本有自己的默认值。
await driver.manage().setTimeouts({
  implicit: 50 * 1000,
  pageLoad: 50 * 1000,
  script: 50 * 1000,
});