Reputation: 587
i have a java code with selenium webdriver to test the presence of some element in a webpage. The test passed each time it found elements but sometime when i have a 500 server error message on the top of the webpage, the test passes successfully. How can i fetch this server error message in my test. What is the web element of this error message?
Any help Thank you
Upvotes: 2
Views: 7575
Reputation: 29042
I've done a check similar to this before in a Regression suite...
One thing you can do, is have a function that gets executed very frequently. Something like this:
(your tags are vague, so i will use pseudo-Java / WebDriver with jUnit)
import static org.junit.Assert.fail;
public void check500() {
if (isPresent(driver.findElement(By.cssSelector("div#500.error"))))
fail("500 page displayed! Failing test, and quitting.");
}
You will, of course, replace "div#500.error"
with whatever element that IS unique within the 500 error page. There's always going to be one. Look around.
Upvotes: 1
Reputation: 787
I do this to catch my errors present on a webpage
try {
List<WebElement> errors = m_driver
.findElements(By.className(ALERT));
//Print all the error messages displayed
for (WebElement e : errors)
log("MESSAGE : " + e.getText());
}
catch (Exception e) {
}
You can replace the By.className by anything else you want.
Upvotes: 0