scala - 如何使用 Selenium WebDriverWait 获得更有意义的失败消息/断言?

标签 scala selenium testing webdriver

当等待条件超时时,我收到非常无用的消息:

Tests in error: 
    myTestName(mySuiteName): Timed out after 10 seconds waiting for              
    com.mycompany.qa.core.SeleniumWebTesting$$anon$1@6818c458

这是 Scala 代码:

  def pageContains(locatorType: String, content: String) {
    locatorType match {
      case "TagName" =>
        val tag = new WebDriverWait(driver, defaultWait).until(
          new ExpectedCondition[Boolean] {
// it times out on this line below, but I can't send out any assert failure or useful message
            override def apply(driver: WebDriver) = driver.findElement(By.tagName(content)).isDisplayed
          }
        )
      case _ =>
        throw new UnsupportedOperationException("No valid locator strategy received (try a valid one, like class name)")
    }
  }

最佳答案

您可以使用withMessage()方法。

WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.withMessage("Your desired Message");
wait.until(new ExpectedConditions(boolean));

关于scala - 如何使用 Selenium WebDriverWait 获得更有意义的失败消息/断言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13281361/

相关文章:

java - hibernate 未找到 hibernate.cfg.xml 文件

Scala:对具有隐式、柯里化(Currying)和默认值的重载方法的偏好

ruby-on-rails - Travis CI "rake db:migrate"或 "rake db:test:prepare"导致 rake 中止! PG::错误:错误:关系 "settings"不存在

performance - JMeter CSV 数据集拆分成线程(用户)

testing - 运行 selenium IDE 脚本时用户手动输入

scala - 使用 Spark ML 时的 VectorUDT 问题

scala - 使用GraphX将有向图实现为无向图

java - selenium 如何测试它是否具有对文件的读取访问权限

python - 如何使用 xpath/css 选择器单击 drupal 8 网站中的动态链接,同时通过 Selenium 和 Python 实现自动化

firefox - 用于 Firefox 的 Selenium IDE Ctrl-Tab