DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Using CSS Selectors in JMeter Scripts

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.

Canberk Akduygu user avatar by
Canberk Akduygu
·
Apr. 26, 18 · Tutorial
Like (5)
Save
Tweet
Share
4.07K Views

Join the DZone community and get the full member experience.

Join For Free

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? Try Loadium now!

CSS

Published at DZone with permission of Canberk Akduygu. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Visual Network Mapping Your K8s Clusters To Assess Performance
  • The Top 3 Challenges Facing Engineering Leaders Today—And How to Overcome Them
  • An Introduction to Data Mesh
  • Top 10 Secure Coding Practices Every Developer Should Know

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: