If an application throws an exception that is a standard which
Selenium can work with. If the software developer is catching the
exception and displaying a custom message to the user in red there is
no standard for this. Typically, a developer will create an invisible
div on all pages. If an error occurs, the code will set the text of
the div to an error message, change the colour of the font to red then
make the div visible. They might be doing something similar but not
exactly the same. What you will need to do is figure out if there is a
pattern the developer is using to display error messages and write a
method to check for error messages. For example, my application has:
<div id="err_msg" style="color: red"></div>
If an error occurs, the javascript will update the DOM so it becomes:
<div id="err_msg" style="color: red">Your error message goes
here.</div>
When I write my automation I would have a method to check the error
message:
public String getCurrentErrorMessage() {
WebElement div = driver.findElement(By.id("err_msg"));
return div.getText();
}
A call to this method with no error message returns "". If an error
occurred it returns the error message text. There is no way to
automatically detect the error message and create a screen shot. I
just know that certain actions may result in an error so I explicitly
look for the error message.