This article will show you how to use Regular Expressions in Gatling tests. Our sample XML based web service is http://www.dneonline.com . We are going to use Adding operation of the web service which allows us to add two number and return the result. Then we’ll extract the sum value via regular expression and make a validation.

Define HTTP Protocol

That’s where we define our base url and other configuration like headers, etc. For this example, all we need to have is baseUrl. For this example, we need to set Content-Type header as text/xml.

Make POST Request to Endpoint

This step is very straight forward. All you need to do is to make a basic POST request. You might want to define the payload in a different variable. For the example, we put it as hard coded.

Extract Result from Response

You need to use check function to be able to extract data. Then you can use regex function with a valid regular expression. After getting the value(s), we use is function to validate the sum extracted from the response.  Sum is once hard coded like the payload.

Setup Test Configuration

We define our scenario by assigning the test case. Then we configure the virtual user number and ramp up times.

Now you can run your Gatling test like a charm.

The whole source code is below:

Canberk.