问题
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).
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.
Use EventFiringWebDriver with WebDriverEventListener and implement proper logging in onError method.
来源:https://stackoverflow.com/questions/18249035/how-to-customize-selenium-test-error-fail-message