How to customize Selenium test error/fail message

爷,独闯天下 提交于 2019-12-12 00:41:02

问题


I'm using VS2012 and i want to customize my selenium tests.

For example, when test fails, i want to show the text The page loaded too long - unable to login + original message instead of showing only this: OpenQA.Selenium.NoSuchElementException: Unable to find element with id == loginElementID. Is it possible? How and when to use Assertions when UI testing? That would make my tests more understandable and informative.

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

Or how to show wait.Message when test fails ?


回答1:


Depending on what you are trying to achieve there are at least two ways of doing it (and probably more).

  1. Use try..catch statement. Catch NoSuchElementException and throw new one with your own message. One way of doing it would be wrapping WebDriver with your own class and then wrapping each method (findBy, get) with try..catch.

  2. Use EventFiringWebDriver with WebDriverEventListener and implement proper logging in onError method.



来源:https://stackoverflow.com/questions/18249035/how-to-customize-selenium-test-error-fail-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!