简体   繁体   中英

Gatling Time Extraction From Response Body

  • 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!

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! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM