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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • What Is API-First?
  • How to Do API Testing?
  • Page Object Model for Performance Testing With Gatling
  • A Complete Keyword-Driven Test Automation Framework with JSON Format.

Trending

  • Rethinking Recruitment: A Journey Through Hiring Practices
  • Fixing Common Oracle Database Problems
  • Unlocking AI Coding Assistants Part 1: Real-World Use Cases
  • Internal Developer Portals: Modern DevOps's Missing Piece
  1. DZone
  2. Coding
  3. Languages
  4. JSON Path Usage for Gatling Tests

JSON Path Usage for Gatling Tests

Learn more about how to extract data with jsonpath.

By 
Canberk Akduygu user avatar
Canberk Akduygu
·
Updated Mar. 05, 19 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
15.0K Views

Join the DZone community and get the full member experience.

Join For Free

As Loadium gives support to the Gatling tool, we thought it would be great to give some tips about Gatling’s data extraction strategies. The purpose of a Gatling test is not different than Apache JMeter test, and that is performing a load test on your application. For a realistic performance test, you need to use dynamic data. To overcome this challenge, you need to extract data from a JSON, XML, or HTML file. Let’s take a look at jsonpath expression usage with some examples.

How to Extract Data With JSONPATH

We are going to use JSON Placeholder web services for JSON Path example.

At first, we need to make an HTTP request to an endpoint to receive a JSON response. For that, we need to create a request to “/todos” endpoint and receive a response body as below.

object Task {
def get_task = exec(http("Get all task ids")
.get("/todos")
}


We create an exec object that makes a get request to /todos. You can change the value in the HTTP object to change its name shown in the reports. When we run the test, our request will receive a response body like below:

[
  {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  },
  {
    "userId": 1,
    "id": 2,
    "title": "quis ut nam facilis et officia qui",
    "completed": false
  }
….
]


Secondly, we need to extract the ids, so we send a specific HTTP request to “todos/id.” So, we change our HTTP request object as below to save all values extracted from JSON.

object Task {

 def get_task = exec(http("Get all task id")
   .get("/todos")
   .check(jsonPath("$[*].id").findAll.saveAs("taskIds")))
}


By using the check function, we are able to validate the response body. Then, we call the jsonPath method and finally save all id values in the taskIds variable. So, we use it in another request.

Then, we loop through all the values that we got from the first request by using for each function. In order to call a variable in your source code, you need to use the ${variableName} structure.

object Task {

 def get_task = exec(http("Get aall task id")
   .get("/todos")
   .check(jsonPath("$[*].id").findAll.saveAs("taskIds")))
   .foreach("${taskIds}", "taskId") {
     exec(http("Get task info")
       .get("/todos/${taskId}")
     )}

}


Now, you are ready to execute your parametrized Gatling test with as many virtual users as you want. Just upload your script on Loadium and monitor the results.

Go loadium.com and execute your Gatling tests

JSON Testing Gatling (software)

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

Opinions expressed by DZone contributors are their own.

Related

  • What Is API-First?
  • How to Do API Testing?
  • Page Object Model for Performance Testing With Gatling
  • A Complete Keyword-Driven Test Automation Framework with JSON Format.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!