1
  • I am completely new to Gatling/Scala.

I have a scenario to execute. Here it goes:

-->Change the shift timings of the employees.

For the above, I am able to script/code the flow. However, I have a challenge: -> I need to extract the "new" time values from the response and check if that matches with the "new" time values being passed through the parameter (csv) file.

Approach/logic: Extract the date values from the response body and compare that with the date value that has been provided in the csv file.

Sample Response:

{
   "employeeId":"xxxxxx",
   "schedules":
   [
   {
  "date":"2019-11-25",
:   :   :   "schedules":
:   :   :   [
:   :   :   :   {
:   :   :   :   :   "employeeId":"xxxxxx",
:   :   :   :   :   "laborWeekStartDate":"2019-11-25",  //New edited time
:   :   :   :   :   "laborWeekEndDate":"2019-12-01",    //New edited time
:   :   :   :   :   "schedules":
:   :   :   :   :   {
:   :   :   :   :   :   "startTime":"2019-11-25T18:15:00.000Z",
:   :   :   :   :   :   "endTime":"2019-11-25T23:45:00.000Z",
:   :   :   :   :   :   "departmentId":xxxxx,
:   :   :   :   :   :   "departmentName":"abc",
:   :   :   :   :   :   "lastModifiedTimestamp":"2019-12-11T09:22:44.000Z",
:   :   :   :   :   :   "breakDetails":
:   :   :   :   :   :   [
:   :   :   :   :   :   :   {
:   :   :   :   :   :   :   :   "startTime":"2019-11-25T21:00:00.000Z",
:   :   :   :   :   :   :   :   "endTime":"2019-11-25T21:15:00.000Z",
:   :   :   :   :   :   :   :   "type":"break"
:   :   :   :   :   :   :   }
:   :   :   :   :   :   ]
:   :   :   :   :   }
:   :   :   :   }
:   :   :   ]
:   :   }

Here, in the below, the right-handside values need to be extracted and compared with the values provided in the csv file.

"startTime":"2019-11-25T18:15:00.000Z",

"endTime":"2019-11-25T23:45:00.000Z",

Please help in performing the above. A step-wise detailed explanation would be much appreciated considering I am totally new to this.

Thanks!

kp4692
  • 11
  • 3
  • do you need to check multiple schedules for the employee? will you need to support multiple employees in a single response? – James Warr Jan 07 '20 at 04:18
  • A little bit of self-advertising ;) in our company we have stopped using Gatling and created a new all-in-code perf testing library - https://github.com/encircled/jPut – Vlad K Jan 10 '20 at 06:47

1 Answers1

0

Disclaimer: I will provide some useful links that should help you in achieving the task. If you will encounter any problems doing it, just post a new question

  1. In order to get a value from a JSON response, you could use a jsonPath HTTP response body. There is an example here, how value can be extracted and saved using this method :JSON Path Usage for Gatling Tests

  2. Reading values from CSV file is possible using a built-in feeder functionality: CSV feeders .Once you have the feeder added, you can reference a value using ${columnName} There is an example here: Step 03: Use dynamic data with Feeders and Checks. After this step you have both values in session. Then using scala language, you should be able to compare those values. Getting a value from session happens using session("variableName").as[String]

  3. For example, you could do a String comparision, if you first substring the value from csv. Scala String comparision Another option is like described here, which is really close to your requirement : How to compare responses from http calls in gatling?

Good luck! :)

anasmi
  • 2,562
  • 1
  • 13
  • 25