Gatling and file variables

At the same time you might wish to replace some of the hard coded values (ie usernames and passwords) with variables as well. It is possible to create lists of values which will be used by Gatling.

These feeder lists will be iterated through with each cycle of your test and the values from that line will be used everywhere that variable name is located.

Partial Soap message

    <soapenv:Body>
       <v1:getAccountData>
          <v1:contributor>
             <v1:contributorId>k.marx</v1:contributorId>             
          </v1:contributor>
          <v1:account>
             <v1:id>${ csvAcctId }</v1:id>
             <v1:idType>acctId</v1:idType>
          </v1:account>
          <v1:keyList>
            <v1:key>keu7</v1:key>
          </v1:keyList>
       </v1:getAccountData>
    </soapenv:Body>
 
 

In this case the “${csvAcctId}” variable is filled from the data file. What makes this really powerful is that this variable can be evaluated by Gatling as part of another variable (string)

Code sample

 val zipgetscenario = scenario("zip test get ")
 .repeat(iterations) {
 feed(csv(AcctFilename).circular)
 .exec( 
 AreaObj.getAccountData
 )
 } 

This one feature is so powerful that it alone could easily be the most important and flexible feature. With a single string body and a csv file you can pass in a lot of varied messages.

In one sense, Gatling, is a similar to LoadRunner for creating load and performance tests. It is similar as you need to write a test program which is run and the analysis of the run is graphed. One difference between LoadRunner and Gatling is that Gatling uses Scala as the scripting language.

There will be people who are either pro or anti Scala but from the standpoint of creating scripts in Gatling it is the language that you use – get over it.

The it doesn’t really matter which programming language or script you use. It may take a while to become familiar with the syntax but all programming languages are to a certain degree arbitrary.

Just like any other language it is possible to create a collection of routines that can be used again and again. Unsurprisingly this is true in Gatling as well.

In my next article I will discuss how this can be done so you can create some reusable building blocks to making the testing process easier.

This entry was posted in programming and tagged . Bookmark the permalink.