Currently, I am writing the automation testing using java and selenium rc.
I would like to verify all the contents present on the user interface, the function is ie below:
public String UITest() throws IOException {
String result="Test Start<br />";
try {
openfile(1);
for (String url : uiMaps.keySet()) {
selenium.open(url);
for (String item : uiMaps.get(url)) {
assertEquals(url+" check: " + item, true,selenium.isTextPresent(item));
result+=url+" check: " + item+" : OK<br />";
}
}
} catch (AssertionError e) {
result+=e.getMessage();
}
result+="Test finished<br />";
return result;
}
the function suppose return a String contains information about the testing. However, the function stopped once there is an assertion error happened.
So, I want to know whether there is a way to ignore the failure and keep executing all the assertion verifications.
Thanks for any help
Don't assert anything in the function. Return say null instead, and have whoever's calling it to keep going but then fail if the function returned null
I'm sure you've figured it out yourself by now: the try-catch should be inside the for loop, not outside of it ;)
From Selenium documentation:
You could use a JUnit 4 error collector rule:
For example you can write a test like this.
The error collector uses hamcrest Matchers. Depending on your preferences this is positive or not.