I am accessing thousands of URLs via Java Selenium. I think some of these are 404s or 500. I want to if the response is other than 200 than throw an exception.
I know Jmeter can do it, I also know it's a bad practice to throw exceptions like this, but due to some limitations in the framework, it can only report exception in final reports. We are capturing exception in JUnit's @After
block
What I tried is this, but it doesn't throw an exception. What am I missing in this code?
if (getDriver().getTitle().contains("404")) {
syso("throw exception, page is 404");
try {
throw new MalformedURLException("page not found");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
consoleLogs("Page found ...");
}
I think it is not throwing exception because I have handled it. But if I don't handle it gives compilation error.
Please help me to fix this.