Why running in command line?

There are different reasons for running the Gatling simulations in the command prompt. The batch file consists of the executable commands which needs to be executed one by one, serially. Another importance of using command prompt is that, it is the only way of inheriting the shell properties which is very much required to run any scripts.

It may be noted that, Apple and UNIX has it's own shell platform like the AppleScript and UNIX terminal. But in case of Windows the command prompt is the only way to run script. There are other ways such as the secure shell , etc , but those are also the Linux properties.

Run the gatling in command line

Open the filegatling.bat

To run the script in the command line interface, the folder containing the gatling.bat must be inside the C Drive of the system. To open the file, go to the bin folder and copy the path. Then, go to the command prompt and change the existing path to the copied path.

Step 1: Copy the path

gatling-bin-path

Step 2: Change the path to copied path:

gatling-bin-path-change

Step 3: Run the gatling.bat inside the command prompt. Wait a few seconds and let the simulations load.

gatling-bat-file-run
After a few seconds, you should see the following on the screen.
gatling-simulation-screen

Before we get the out required file in the simulation list, it is required to copy our Scala script into the result in the Gatling folder itself. The simulation we require will appear along with the other lists with the simulation number. First we copy the Scala scripttest01.scala into the result folder

gatling-result-folder

Run the simulations

To run the simulations select the simulation number and press enter. In our case out simulation number is 6 as the test01.scala comes at this number. gatling-selected-simulation

After selecting the appropriate simulation number, we could be asked to write a description about the simulation. In the description, we are supposed to write anything of our choice, but it is advisable to use keywords related to our test scenario.

For example: anythingofmychoice not including any extra spaces while writing the description. gatling-run-description

After writing the description and hitting enter we should be able to the below screen, showing all details about the test scenario.

gatling-command-line-output

Now as the report is generated, it's corresponding html file is also created inside the folder results.

Analyzing the report.

These are the different charts obtained after the index.html file of the required simulation is run:

Chart 1: Global Information

This chart mainly shows about how response times are distributed over standard ranges. The OK/KO requests are shown on the right panel.

In our case, the request number was 10 but, it did not reach up to ten. Instead, we interrupted killing the process. This file can also be modified by editing the file gatling.conf inside the gatling folder itself. gatling-global-report

Chart 2: Statistics

The top panel of the statistics chart is broadly divided into two parts. One is the Execution and the other is the Response Time. The statistics chart also shows some of the standard statistics such as the min, max, average, standard deviation and percentiles globally and per individual request also.

We should also mention that, if our scenario contains groups, then each group is a non leaf node, and each request is a descendant leaf of a group.

Group timings are generally the cumulative response times of all the elements inside the group. The duration of a group can be displayed instead of group cumulative response time by editing the filegatling.conf. gatling-statistics

Chart 3: Active Users

The Active users chart displays the active users at the time of the simulation of the Scala file. Total and individual scenario active users tries to represent a mix of arrival rate and the number of concurrent users.

The Active users chart is computed in the following way. Number of previous users at the previous second plus the number of users that started during this second plus the number of users that were terminated during the previous second. The number of active users can be an abstract way to analyzing the traffic in the website of any of the web applications. gatling-active-users

Chart 4: Response Time Distribution

This response time distribution chart shows the response time distribution of the response times. The next chart show the complete response time distribution in percentiles. gatling-response-time-distribution

Chart 5: Response time in Percentiles

The response time in percentiles chart shows different responses over time, in percentiles. This chart only works for successful requests. It may be noted that any failed requests can end prematurely, or it may be caused to timeouts. If so happen, that would cause a drastic effect on the percentile computations. gatling-response-time-percentile

Chart 6: No of Requests

The request per second chart shows the number of requests sent per second over time. gatling-request-per-second

Chart 7: No of Responses

The Response chart shows the number of responses received in one second over time. gatling-response-time

Manipulating the Scala script

It may be noted that the Scala script will be executed in default without the functions inside being modified by the user.

But the Scala script can be modified by the user to change the parameters of the functions to get customized out. Therefore, it is mandatory to learn some of the basic Scala syntaxes to get

desirable output in the graphical format.

Below we will use some Scala functions with their uses:

  • Check:
  • The check API can be used for two things. One is to verify that the response to a request is matching expectations. Other is for eventually capturing elements in it. Checks are performed on a request with thecheck method. For example. HTTP Request:

    http("My Request").get("myUrl").check(status.is)(200)). It should be added that not only, one check functions, but many check functions may be used to perform various tasks.
  • Page location:
  • One is currentLocation: This function targets the current page absolute URL. This can be used to check, whether the page to which it is redirecting, is the expected one. The other is the currentLocationRegex(pattern): This function applying regex on the location.

    By default is can extract 0 or 1 capture group, so the extract type is String. currentLocationRegex(pattern).ofType[T].Gatling allows us to use Tuple number from Tuple2 to Tuple8.
  • HTTP header:
  • One type is header(headerName). It targets the HTTP response header of the given name. It may be notified that, headerName may be a plain String or any String using Gatling EL or an Expression[String].

    The other type is headerRegex(headerName, pattern) In this case, pattern is used to apply a regex on the header value. HTTP response body: This may include more than four different functions.

    responseTimeInMillis: This function will return the response time of the request in milliseconds which equals the time between starting to send the request and finishing to receive the response.

    bodyString:It returns the full response body String. It may be noted that this can be matched or compared with the content from the the file system.

    bodyBytes:It returns the full response body byte array.

    substring(expression):It scans for the indices of a given substring inside the body string. It can be noted that an expression can be a plain string, a string using Gatling EL or an Expression[String].

    regex(expression): It defines a java regular expression which can be applied on any text response body. Example: regex("""/school/details/teachers/(tcno[0-9]*)/operations.html""")

    regex(expression).ofType[T]:Gatling provides built-in support for extracting String tuples. Tuples ranges from Tuple2[String] to Tuple8[String].

  • Validating :
  • There are several validation functions which are available.Some of them are listed below with their functions.

    is(expected): It checks whether the value is same as expected.

    not(expected):It checks whether the value is different from the expected one.

    exists: It check whether the value exists and is not empty in case of multiple results.

    notExists: It checks whether the value does not exists and is empty in case of multiple results.

    in(sequence): It checks whether the value belongs to to particular sequence.

    Saving:Similarly there are function for saving also.

    saveAs(key): Saving is an option for storing the result of the previous steps of extraction or transformation into the virtual user Session, which can be reused later.

    And the last one is: checkIf(condition)(thenCheck)

Conclusion

So, far we have seen how to install Gatling and JDK. Then we have seen how to create test performance scenarios and then we have seen how to run the Scala script, and how to create the graphical interpretation of the test report.

We have also understood the different parameters in the output of the Gatling. Then we have also seen how to read and understand the script and also how can we modify some functions by knowing the work done by those functions.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions