Friday, November 1, 2019

How do you identify broken links in Selenium Automation?

When we are asked to identify the broken links in the application, what we do? Collecting all the links on the page to a list and looping through links, clicking on links one by one and verify whether the content on the next page displayed or not?

This process is time consuming, and not that effective as it involves multiple to and fro actions. We can identify the broken links without clicking on the each link using Rest-assured (Java API Library). If you wish to know more about rest-assured click this link. Lets jump into coding part.

Search for "rest-assured maven dependency" in Google. Then copy the latest version of rest-assured dependency of "io.rest-assured" as shown in the below screenshot. Add it to your pom.xml file.



In Rest-assured, we have a Http method called "GET", this method is used for retrieving the information from the server. If the link is not broken the server sends response with status code 200 (OK), if the link is broken we receive it sends the status code 404 (Not Found). We use the same logic in our test case.


As shown in the above program, we get the status code of each link and we verify whether it is equal to 200 or not. If not 200, we the link is considered as broken link.

Check the result in the screenshot below


This is how we can identify the broken links using Rest-assured easily.

#HappyTesting #HappyLeaarning #qababu

No comments:

Post a Comment

How do you identify broken links in Selenium Automation?

When we are asked to identify the broken links in the application, what we do? Collecting all the links on the page to a list and looping t...