JMeter Webpage status check

Learn how to check the status of a web page using Apache JMeter on Windows. This step-by-step guide covers JMeter installation, configuration, test execution, and result analysis for effective website performance and uptime monitoring.

Installation

Step 1: Install JMeter

The first step is to install the Apache JMeter Tool. Open any browser and search Apache JMeter download or access the following URL: https://dlcdn.apache.org//jmeter/source/apache-jmeter-5.6.3_src.tgz

Configuration

Step 1: Configure and launch JMeter

After installing Apache JMeter on your machine, launch the JMeter (window batch file), and it will redirect you to the JMX, where we can add our samplers, listeners, requests, etc., to the Test Plan.

Image showing a sample JMX file

Step 2: Configure the JMX in JMeter

When the JMX file is ready and set to add the Testplan, Thread group, etc.
Right click on the testplan → Add → Threads(Users) → Thread Group

After adding the Thread Group
Right-click on the Thread Group → Sampler → HTTP Request

Now we have our Test plan, Thread Group, and HTTP Request ready.
We can configure the name of the thread group and HTTP request to fit our criteria.

Test plan, Thread Group, and HTTP Request are configured.

Step 3: Configure HTTP Request Sampler in JMeter

Inside the HTTP Request Samplers, we configure and add the Sites to check and define responses that need to be configured.

HTTP Request Sampler that we can use to configure the Sites, Protocol, Port number, HTTP Request type, Path if specified, etc. All these data are stored and managed inside the HTTP Request.

JMX file where the HTTP Request is configured for the VMState Site.

Step 4: Add User-Defined Variables to HTTP Request Sampler in JMeter

User-defined variables help check and verify the content of the Site given inside the HTTP Request Sampler.

Right-click on the Thread Group → Config Element → User-Defined variables

We can define the Text or Code, etc. Inside the User Defined variables and customize our criteria.

To Check that, we need to declare the Name, Value, and Description inside the User-Defined variables.

Sample Example:

  • We can define the Name for the VMState Sites as EXPECTED_TEXT
  • We can define the Value for the VMState Sites as All Rights Reserved
  • We can define the Description for the VMState Sites as: Expected text for VMState
  • The Input may change with your Thread group and Site, which needs to be checked.

On the basis of the Defined Name, Value, and Description inside the User Defined variables will be the Groovy script, which will be added to the JSR223 Postprocessor, which will be explained in the next section.

User-defined variables to check the Text “All Rights Reserved” after accessing the website

Step 5: Add JSR223 PostProcessor to HTTP Request Sampler in JMeter

After configuring the User-defined variables, we need to set up the JSR223 Postprocessor for our HTTP Request Sampler.

Right click the HTTP Request → Add → Postprocessor → JSR223 Postprocessor

JSR223 Postprocessor will be added, and Inside the JSR223 Postprocessor, we can customize our Response message that needs to be printed as a result

In the JSR223 Postprocessor, select the Groovy scripting engine and add a custom Groovy script, for example:

Sample code: This Sample code shows the Groovy script for the VMState Sampler, which will check the Site if the response is 200, then it will print: Site is up, or Site is down

// JSR223 PostProcessor Script
String responseCode = prev.getResponseCode();
String responseData = prev.getResponseDataAsString();
String expectedText = vars.get("EXPECTED_TEXT"); // Change this per site

if (expectedText == null || expectedText.trim().isEmpty()) {
    prev.setResponseMessage("Expected text not defined");
    prev.setSuccessful(false);
    return;
}

if (responseCode == "200" && responseData.contains(expectedText)) {
    prev.setResponseMessage("Site is up");
    prev.setSuccessful(true);
} else {
    prev.setResponseMessage("Site is down");
    prev.setSuccessful(false);
}

JSR223 Postprocessor and the Groovy script

Step 6: Add a Simple Data Writer to HTTP Request Sampler in JMeter

After adding the JSR223 Postprocessor, a simple data writer will be added to fetch the CSV result and the contents that will be obtained from the JMeter Check.

Right-click Test Plan → Add → Listener → Simple Data Writer

Simple Data Writer is the functionality that generates and stores the results in CSV format. We can also configure the obtained result with the required outputs that we need.

We can configure the Simple Data writer accordingly with the required headers.

Note: Browse the path where the .csv file needs to be saved using the Filename option.

Simple Data Writer Configuration Checkbox

Simple data generated CSV results.

Conclusion

You have now successfully implemented a JMeter site checkup on Windows. This process enables you to monitor website performance and uptime effectively, ensuring smooth operations and quickly identifying any issues. Customize your JMeter scripts and configurations to match your specific testing needs, and periodically review the setup to adapt to any changes in your environment or requirements.

Post a comment