JMeter – Find Broken Links

In this post, Lets see how we can use JMeter to find all the broken links for a given URL.

Wait a minute! Are we going to use JMeter to find the broken links on a web page? Is JMeter not for performance testing?

Yes, JMeter is a performance testing tool. But It can also be used for your functional testing! I do a lot of functional testing with JMeter. Actually JMeter is like any other web browser (Chrome/FF/IE etc). But there are few limitations.

  1. It does not execute JavaScript like your web browser. (It makes sense for JMeter not to execute the js files as it was designed for performance testing the server. Not your local machine which will execute the js files)
  2. It does not make AJAX calls in parallel.

So, If we know the limitations of JMeter, we know where to use it. Apparently it can not be used to verify if the text boxes are aligned properly in the UI or not when we access the web page. But we can use JMeter to validate the HTML source.

Why not simply use UFT/WebDriver? We can! But JMeter is very fast & easy to implement!

To simply put, if it is not UI validation, then You can use JMeter for your functional testing as well assuming you know the limitations of JMeter.

 


Lets see how to create a simple test plan in JMeter to find the broken links on a given page. (Please note that there are many tools/browser plugins available to find broken links. But our aim here is to see how JMeter can be used for this purpose/just to give you an idea. I am not arguing here that JMeter is the best tool to find broken links).

  1. Lets launch JMeter
  2. Add a Thread Group
  3. Add a HTTP Request under Thread Group
  4. Update the URL of the web page on which we need to find the broken links
  5. Add a ‘Regular Expression Extractor‘ under the HTTP Request
    • This is to extract all the links.
    • Expression would be (href|src)=”(.*?)” (get all the href/src attributes values)
    • Template would be $2$ (we need the second sub match which has the URL/Path to be checked)
    • Match No would be -1 (to get all the matches)
  6. Add a ForEach Controller (To iterate all the links)
  7. Under ForEach controller, Add a HTTP request (this is to send the HTTP request & see if the given link is broken or not)
    • Optional: We can add a HTTP request under a ‘If Controller’ to handle href attribute values like ‘#’ ot to skip certain patterns. Or we can update the Regular expression pattern to get only the matching URLs in the step 5.
    • Optional: We can also add a ‘Beanshell PreProcessor’ under this HTTP request to do any pre-processing.

Simple Test Plan to find Broken Links:

jm-brokenlink-test-plan

Now Lets assume we have a huge list of URLs/Pages for which we need to find the broken links.

Lets modify the above test plan as given below. (like creating a reusable function using Test fragment/Module Controller)

jm-brokenlink-test-plan-mod

In the above example, We have the list of URLs in CSV file. Main aim of the thread group is to read the URLs from CSV file & give it to the Module controller.

‘Broken Link Finder’ module is responsible for finding all the broken links.

By designing this way, we can call the ‘Broken Link Finder’ as and when we want in your test plan.

Summary:

JMeter can save a lot of our time if we can implement it correctly for our functional test requirements like this. We can also use JMeter to do certain data setup. For ex: In my project, I use JMeter to create thousands of test users, to quickly verify if the servers are up and running etc.

 

Share This:

1 thought on “JMeter – Find Broken Links

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.