【问题标题】:How to customize Selenium test error/fail message如何自定义 Selenium 测试错误/失败消息
【发布时间】:2013-08-15 08:36:44
【问题描述】:

我正在使用 VS2012,我想自定义我的 selenium 测试。

例如,当测试失败时,我想显示文本 The page loaded too long - unable to login + original message 而不是只显示这个:OpenQA.Selenium.NoSuchElementException: Unable to find element with id == loginElementID。是否可以? UI 测试时如何以及何时使用断言? 这将使我的测试更易于理解和提供更多信息。

var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 0, 8));
wait.Message = "Page Loaded too long";

或者测试失败时如何显示wait.Message?

【问题讨论】:

  • 您是在使用提供日志记录到文件的框架,还是只是在谈论更改控制台中的输出?

标签: visual-studio-2012 selenium ui-testing nosuchelementexception


【解决方案1】:

根据您要达到的目标,至少有两种方法(可能更多)。

  1. 使用 try..catch 语句。捕获 NoSuchElementException 并使用您自己的消息抛出新异常。一种方法是用您自己的类包装 WebDriver,然后用 try..catch 包装每个方法(findBy、get)。

  2. 将 EventFiringWebDriver 与 WebDriverEventListener 一起使用,并在 onError 方法中实现正确的日志记录。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2021-05-19
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 2012-07-28
    • 2015-11-21
    • 2015-04-09
    相关资源
    最近更新 更多