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

4 comments:

  1. It would not be fair if we compliment all the blog writings but not the author.
    Automation testing

    ReplyDelete
  2. Nice post. Useful information. This is always happy to know about Salesforce training in Gurgaon whose certification program helps many to get certificed. I strongly urge you to join now in Salesforce Training in Hyderabad | Course Price | Training institute and enroll for free demo at Salesforce Training in Bangalore | Course Certification Cost and Job Placement Assistance . I have gone through this Salesforce Certification Training. Why done you enroll for a free demo at Salesforce training institutes in Chennai [updated] | Course Price

    ReplyDelete

Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...