So basically I have achieved this task by verifying for broken links(i.e we need to check the link which is pointing to wrong URL or invalid URL).
So if the link is pointing to a wrong or invalid URL, we get a 404 page not found error an issue in most web applications which is called Broken Link.
Below I have explain the implementation logic and my own approach:
First extract all links on the site as follows, List list=driver.findElement(By.tagName("a"));
public static int getResponseCode(String urlString) throws
MalformedURLException, IOException {
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.connect();
return huc.getResponseCode();
}
No comments:
Post a Comment