JMeter Tutorial | Web Performance Testing Tips and Tricks

JMeter tutorial is ready for Web Performance Testing. I will share information about how to do web performance testing or in other terms web load testing by using Apache JMeter.

I will use isinolsun.com website as an example. First, we will define our performance testing scenario, then record our scenario, after that clean unnecessary requests and finally add required JMeter components to create a more realistic performance testing script.

JMeter Tutorial First Step: Define Web Performance Testing Scenario

Our scenario for Jmeter tutorial is described as follows:

  • Go to https://www.isinolsun.com.
  • Go to the job listing page.
  • Select a job to go its details.
  • Go to the selected job’s details.

Record the Performance Testing Scenario

First, you need to open JMeter and right-click the Add Plan and then select HTTP(S) Test Script Recorder.

jmeter tutorial

If you want to retrieve all embedded resources, you should check this checkbox. Also, you need to select the following options. Also, set the port value as 8888.

Open a Firefox browser and go to Network Settings and do Manual Proxy Configuration” as follows.

Then, start the recording by clicking the Start button.

and you will see the below screen. Click OK to continue.

Then, let’s import JMeter certificate to Firefox. In Firefox, Privacy & Security and click View Certificates.

Then, click the import button.

Select the ApacheJMeterTemporaryRootCA.crt certificate.

and click OK.

Now, open https://www.isinolsun.com website on Firefox and execute the given scenario. Note: Please make sure firefox manual proxy port has been set to “8888”. Double check this. If it was not set, please set it as 8888. You will see the below status when you will start to do the recording.

I recorded a scenario which comprises of listing the jobs and then click on a specified job detail. The recording result is shown below.

Now, we can stop the recording by clicking Stop button.

Now, we should clean the recording results and add extra features.

Clean Recording Results 

I removed, HotJar, Google Apis, photos, text files etc. as shown on below screenshot. You need to check each request and remove these kinds of unnecessary requests.

Then, my scenario’s requests looked like as shown below.

Let’s add a Thread Group and move all requests into it.

The final status will look like as below screenshot.

Now, we can run a test but before doing this, it is better to add a View Results Tree to see the requests and response details.

Click start to run execution.

You will see the results by clicking View Results Tree. Also, you can see request and response data with several formats such as text, HTML, JSON, etc.

Let’s check the Job Detail request’s Request Data. As you see below, we should click the related request, then Request tab. Then, we can see the request’s detail. Here, we have a GET request as shown below.

jemeter tutorial

Now, Let’s look at the Job Listing request and try to collect all job links then send them to Job Detail request as a parameter so we can randomly visit a job detail. This is a more realistic scenario. If we increase virtual user number, each of them will visit random job detail pages.

jmeter download

As you see the above screenshot, we need to get the URLs of the jobs. We can get this in several ways such as Regular expressions extractors, CSS extractors, XPath extractors, JSON extractors etc. Let’s try one of them. Let’s try CSS extractor. First, it is better to go to job listing page on Chrome and select an appropriate CSS selector. My aim is to find a proper CSS selector which covers all jobs URLs. As you see below “search-list-wrap a” covers all URLs of the jobs. Also, you can learn more about CSS selectors in this article. http://www.swtestacademy.com/css-selenium/

what is jmeter

And I will use Ranorex Selocity to verify my selection. http://www.swtestacademy.com/ranorex-selocity/
As you see on below screenshot, I found all job URLs. Now, I need to send them to the Job Detail request as a parameter.

jmeter interview questions

Now, we need to use this CSS selector on JMeter to check its functionality as shown below. Select the CSS/JQuery Tester, then write selector as “.search-list-wrap a” and then write “href” as an attribute then click Test button. You will see all 20 links.

jmeter load testing

Now, the question is how to retrieve these links and use as a parameter and select them randomly for Job Detail request. In order to accomplish this operation, we should use CSS/JQuery Extractor as shown below screenshot.

performance testing tools

We should set the required fields as follows:

Variable name = job (you can give any name you want.)

CSS/JQuery expression = .search-list-wrap a  (we should write our CSS selector.)

Attribute = href  (we need to write required attribute of the selector.)

Match No. (0 for Random) = 0 (you can select 0 for random selection)

stress testing

Then, we need to go to Job Detail request and change Path with our previously defined job variable. Before the changes, Job Detail request is shown below.

endurance testing

After the change, the request should be like that.

apache jmeter

Now, let’s run our JMeter script. As you see below screenshot, our performance test works without any problem and we can run it with a randomly selected job variable.

Now, we can add multiple users with the loop controller or increasing threads. Let’s increase the thread and run the test for multiple users. I change the Thread Properties as 10 users, 2 thread, and 2 loop count. Thus, we will have 20 requests because our thread number is 10 and loop count is 2 then we should multiply these values 10*2=20. And ramp-up time is 2 seconds.

When we run the test by clicking the green run button, we will get below results on View Results Tree. As you see below, each time we go to random job detail.

In this way, you will create your own scenarios, run them and analyze your project’s performance bottlenecks. You can also add other listeners to analyze results such as Summary Report.

Also, you can import your JMeter scripts to some cloud services and run your performance tests with incoming virtual users generated by cloud servers and analyze the results on the informative and beautiful reports. Loadium is the cloud-based performance and load test solution that provides these services.

Regular Expression Extractor

We can also use other extraction methods to retrieve specific response data. I explained you CSS/JQuery Extractor but you can also use Regular Expression Extractor or JSON Extractor. In order to do this, you need to click Post Processors and select Regular Expression Extractor.

Then, go to response data (Run the test, Click View Result Tree, Click Response data), then select the specific part of the response and copy it. Then, paste it into Regular expression testing box, and then we should replace the text that we want to retrieve with this regular expression (.+?) When you click the Test button, you will see the results. As you shown in below screenshot, the [1] elements are our job details URLs.

Now, we should copy our tested regular expression and paste it into Regular Expression text box on Regular Expression Extractor window.

Then, in order to test this variable, I used it on HTTP Request name as ${jobByRegEx}

Then, I run the test and saw that it worked without any problem.

JMeter Timers for User Think Time

In real life, users wait on job listing page for a while and then open a job detail which they like. In order to provide this functionality for our web performance script, we will add JMeter Timers. There are several timers available in JMeter but the basic one is Constant Timer. It waits for a specified time. In this JMeter tutorial, we will use this JMeter Timer. Let’s add 3 seconds of think time for job selection, on the job listing page. To do this, we should right click on Job Listing request and add Constant Timer as shown below.

Now, we can add 3000 milliseconds wait time for job selection.

Then, I set my thread number to 3, and run the test. This time, I saw that my execution waited on Job Listing page for 3 seconds. The result is shown below. In this way, you can add several think times to your performance test, load test, stress test scripts.

There are many options available in JMeter to fulfill your performance testing scenarios. You can use any of them when needed. In this JMeter tutorial, I tried to explain an example scenario for web performance testing with Apache JMeter. In the following JMeter tutorial series, I will explain how to do API performance testing with JMeter.

I hope you enjoyed reading my JMeter tutorial.

Here is the sample script link: https://github.com/swtestacademy/web-performance-testing-jmeter

Thanks.
Onur Baskirt

Leave a Comment

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