The only way is messy. Coded UI works with assertions which are intended to be interpreted as "[something] should be true here and, if not, stop immediately failing the test".
There are various approaches to avoiding the "stop immediately" part, but most boil down to code of the style:
try {
... an assertion ...
}
catch (...)
{
... remember and/or report the detail of the failed assertion ...
}
try {
... another assertion ...
}
catch (...)
{
... remember and/or report the detail of this failed assertion ...
}
if ( any assertion above was caught OR anything was remembered )
{
// Something failed.
report the remembered items
Assert.Fail(... some message...);
}
The try...catch...{}
can be repeated as necessary. The catch
clauses can be difficult to write unless you only catch the most general exceptions. The code that does the reporting and remembering may throw exceptions. Between the try...
statements there may be calls of non-assertion methods that may fail, so these would also need to be wrapped in try...
statements. The whole test gets very cumbersome and risks having faults that are detected and remembered but not reported because of a later unhandled exception.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…