0

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

例如,当测试失败时,我想显示文本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 ?

4

1 回答 1

0

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

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

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

于 2013-08-16T21:07:35.430 回答