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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Component Tests for Spring Cloud Microservices
  • Setting Up a CrateDB Cluster With Kubernetes to Store and Query Machine Data
  • Solid Testing Strategies for Salesforce Releases
  • Apex Testing: Tips for Writing Robust Salesforce Test Methods

Trending

  • Implementing Explainable AI in CRM Using Stream Processing
  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 2
  • Agentic AI Systems: Smarter Automation With LangChain and LangGraph
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. How to Use RegEx Extractor in Gatling Projects

How to Use RegEx Extractor in Gatling Projects

Learn more about using the RegEx Extractor to extract data in performance test projects.

By 
Canberk Akduygu user avatar
Canberk Akduygu
·
Mar. 13, 19 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
9.0K Views

Join the DZone community and get the full member experience.

Join For Free

Regular expressions can be very powerful with string manipulation. They are fast and flexible but a little bit hard to learn. To be able to extract data in performance test projects, the regular expression is a good fit. Gatling supports regular expression usage for data extraction. Let’s see how we can integrate this approach into our Gatling projects.

How to Extract RegEx in Gatling Script?

For this example, we are going to use an XML web service hosted on www.dneonline.com

There is a calculator web service where you can do addition, subtraction, multiplication, and division operations.

Execute POST Command

First, we need to post body data to our web service. We create an exec object that will make a post operation with a body. Body type can be changed according to your web services nature. We are using StringBody, as we are going to post a string. The XML payload is hardcoded for this example. But you can always create a variable to store the payload.

def get_task = exec(http("Addition Task")
.post("/calculator.asmx?op=Add")
.body(StringBody("""<?xml version="1.0" encoding="utf-8"?>
                        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                          <soap:Body>
                            <Add xmlns="http://tempuri.org/">
                              <intA>100</intA>
                              <intB>200</intB>
                            </Add>
                          </soap:Body>
                        </soap:Envelope>"""))


This scenario will work like a charm. But that’s not enough. We need to validate the response.

We can do different response validations, including status and content validation. This time, we will validate the content.

Extract the Data

Secondly, you need to add the check method. This method is where you will make all the validations. Then, we add gatling regex method inside of it with a valid regular expression.

def get_task = exec(http("Addition Task")
 .post("/calculator.asmx?op=Add")
 .body(StringBody("""<?xml version="1.0" encoding="utf-8"?>
                        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                          <soap:Body>
                            <Add xmlns="http://tempuri.org/">
                              <intA>100</intA>
                              <intB>200</intB>
                            </Add>
                          </soap:Body>
                        </soap:Envelope>"""))
 .check( regex( "(?<=<AddResult>)(.*\\n?)(?=</AddResult>)" )))


Validate the Data

Whenever you run tests, you will see that the test has passed. What is missing here is the validation. We use the is method to make the validation against the extracted value. As our test data is hardcoded, we can also hardcode the result.

def get_task = exec(http("Addition Task")
 .post("/calculator.asmx?op=Add")
 .body(StringBody("""<?xml version="1.0" encoding="utf-8"?>
                        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                          <soap:Body>
                            <Add xmlns="http://tempuri.org/">
                              <intA>100</intA>
                              <intB>200</intB>
                            </Add>
                          </soap:Body>
                        </soap:Envelope>"""))
 .check( regex( "(?<=<AddResult>)(.*\\n?)(?=</AddResult>)" ).is("300") ))


So, let's review what we did step by step:

  1. Created a POST command that makes a request
  2. Parseed the response with a regular expression
  3. And made validation

Happy load testing! 

Gatling (software) Web Service Test data

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

Opinions expressed by DZone contributors are their own.

Related

  • Component Tests for Spring Cloud Microservices
  • Setting Up a CrateDB Cluster With Kubernetes to Store and Query Machine Data
  • Solid Testing Strategies for Salesforce Releases
  • Apex Testing: Tips for Writing Robust Salesforce Test Methods

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!