Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using CSS Selectors in JMeter Scripts

DZone's Guide to

Using CSS Selectors in JMeter Scripts

Take a look at this tutorial that will show you how to construct CSS Selector to extract data from your webpage for performance analysis.

· Performance Zone ·
Free Resource

Container Monitoring and Management eBook: Read about the new realities of containerization.

When performance tests are executed, the main focus is on how the application behaves under heavy load. To analyze it, you need to extract data from a web page and create a new request with the retrieved value. Or you just need to parse the response and validate an assertion. To deal with these challenges efficiently, you can use CSS Selectors. In this article, we’ll go through the basic usage of CSS Selectors in JMeter scripts. If you need more on this topic, please feel free to contact me through our contact us form with the message subject as “CSS Selectors”.

Let’s See CSS Selectors in Action!

We have an HTTP Sampler which makes a GET request to a landing page e-commerce website. In the main page, products are listed. To make a randomized navigation from the main page, the URL of the new pages needs to be extracted. To do this:

  • Add a CSS Extractor which will fetch the URLs.

Image title

Extracting Data from Response

The ProductLink Extractor looks like the above figure.

  • The "Reference Name" field needs to be filled out. This variable will be used in different places with this reference name.
  • The CSS/JQuery expression should be detected from the console of your web browser. If you are familiar with Selenium, you won’t have any difficulty.
  • The "Attribute" field defines the attribute of the extracted web element.

Image title

  • In order to make a GET request to a random link from a list, you should enter “0” in Match No.
  • Set default value to NoLinkFound  or a valid product Link.

Making a New Request

  • Fill your second HTTP sampler’s Path field with the productLink variable by using ${variableName}   syntax.
  • Set the Name of the HTTP sampler with the same variable so you will be able to understand which pages you hit during the test run.

Jmeter Selectors





By doing so in every run, you will visit a different link.

Image title

How to Debug the CSS Selector

  • Add a “View Result Tree” listener in your Thread and run your test once.
  • After the execution, open “View Result Tree” listener and switch to CSS/JQuery Tester View.

There, you can debug your CSS expression in JMeter.

Image title

Do you want to run your JMeter test in the cloud? Come to loadium.io.

Take the Chaos Out of Container Monitoring. View the webcast on-demand!

Topics:
performance and testing ,jmeter ,load test ,performance ,css selectors

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}