I think the best way to start learning JMeter is to script a user journey through a web application; logging in, searching for and adding items to a basket, checking out, the usual stuff.

Some of the steps to achieve this are actually quite complicated once you start digging into the detail, so I’m going to split them up over a series of posts. This one covers navigating to a web page and asserting that it’s the correct one once you get there.

If you’re following along, the first things you’ll need to do before we actually get into the details are:

  1. Open up JMeter. I’m assuming that you’ve downloaded it and installed it on your machine. If you haven’t, you can download it from here. I use the word installed loosely since, as long as you have a Java Runtime Environment [JRE] on your machine, JMeter should work fine. If you have some problems with this step then they’re probably machine/environment specific; I recommend a quick hunt for the solution via your favourite search engine.
  2. Once JMeter is open – right click on the Test Plan icon and add a Thread Group via Add > Threads (Users) > Thread Group. Don’t worry too much about what a Thread Group actually is at this point; I’ll cover that some other time.
  3. Right click on the Thread Group and add a Simple Controller via Add > Logic Controller > Simple Controller
  4. Right click on the Simple Controller and add a HTTP Request via Add > Sampler > HTTP Request

A blank HTTP Request looks like this:

blank http request

There’s a lot of stuff there that you don’t need right now. You only need to fill out the Name, Server Name or IP and Path fields so they look like the below:

http request

Having done so – your Test Plan should look more or less like the below:

test plan

Notice that I’ve given my Thread Group and Simple Controllers meaningful names. It’s not crucial that you do that right now, but once your tests become more complex, it will be.

If we go ahead and run our test now (by clicking on Run > Start in the file menu, or the green Play button), we’ll see something has happened, but we’ve no way of checking exactly what at the moment. You need to add a Listener to show you what’s going on with your test. Do that now by right clicking on the Test Plan icon, then Add > Listener > View Results Tree.

3D348A98-3F55-4D63-BDCD-2DE377A3A8B0

Now click on the View Results Tree icon and run the test again. You should see a result like this:

result

A Response Code of 200 means our HTTP Request was fulfilled ok. Some of the other results may be of interest too, but I’ll cover those another time.

Clicking on the Response Data tab and then selecting the HTML view (in the dropdown just above the Scroll automatically checkbox) will render some of the HTML for us.

result html

It looks kind of basic because JMeter doesn’t load the other page resources (images etc) by default. We can ask it to, but there’s no need right now.

By looking at the response we can see that the page we requested has been returned, but we need to add some kind of check to do that for us in future. We want JMeter to carry out an assertion on the page and verify that it can see what we think it should see. Probably the simplest thing to do at this stage is to check for something specific to prove we’re on the correct page.

In the HTTP response we can see the text “Your Amazon.co.uk”.

result html with Amazon

If I switch to text view in the response data and do a Search for the same text, JMeter finds it ok – which suggests to me it’s a good candidate for an assertion. So let’s add one by right clicking on the HTTP Request and adding an assertion via Add > Assertions > Response Assertion

result plain text view

Open up the Response Assertion and click on the Add button at the bottom of the page. This adds a new assertion pattern. To verify that our assertion is going to do the right thing, let’s start with a failing test. Add the word “TESTING” into the assertion pattern so it looks like the below:

assertion

Now run your test. It should fail.

Expanding on the failed response will open up the Assertion result, and you should see something similar to the below:

failed test

Now add the text “Your Amazon.co.uk” to the assertion pattern instead of “TESTING” and run your test again.

passing request

You should see a green result again in the Results Tree, indicating that the assertion was successful.

Congratulations. You have your first passing JMeter test! 🙂

Next I’ll move onto logging-into Amazon, which is significantly more complex. Stay tuned!

Thanks for reading. Feel free to reach out via a comment or on the socials if anything resonates.