Using the session variable the in consecutive check method using JSON path

I want to get value of “@id” for “hardwareId”: “-1517125410” and using the value of “@id” get the expiration date where “hardwareId” == “@id

For e.g.: For “hardwareId”: “-1517125410”, value of “@id”: “2432ef7a-ada4-4357-812d-6b0bbe90ed6f”
And in licenses array , “hardwareId”: “2432ef7a-ada4-4357-812d-6b0bbe90ed6f”
get the value of “expirationDate”: “2023-05-16T23:59:59.027+00:00”

Request: GET

Code:

{
  "hardwareIds": [
    {
      "@id": "2432ef7a-ada4-4357-812d-6b0bbe90ed6f",
      "id": 32206,
      "hardwareIdString": "-1517125410",
      "details": null,
      "hardwareId": "-1517125410"
    }
  ],
  "licenses": [
    {
      "@id": "42010c27-a075",
      "id": 34454,
      "hardwareId": "2432ef7a-ada4-4357-812d-6b0bbe90ed6f",
      "user": "e4771618-9f1d-402c-b924",
      "expirationDate": "2023-05-16T23:59:59.027+00:00",
      "maintenanceDate": "2023-05-16T23:59:59.027+00:00",
      "enabled": true,
      "productProfile": "fdd4536d-fb5f",
      "profileRole": "2c79ef63-bd3c-",
      "createdDate": "2023-03-09T06:14:32.560+00:00",
      "modifiedDate": "2023-03-17T08:55:17.137+00:00"
    },
    {
      "@id": "baa20043-49e0-41a3-9256-68c2adff1ad5",
      "id": 34453,
      "hardwareId": "2432ef7a-ada4-4357-812d-6b0bbe90ed6f",
      "user": "e4771618-9f1d",
      "expirationDate": "2023-05-16T23:59:59.027+00:00",
      "maintenanceDate": "2023-05-16T23:59:59.027+00:00",
      "enabled": true,
      "productProfile": "490a57be-0904",
      "profileRole": "3da6da45-fed5",
      "createdDate": "2023-03-09T06:14:32.560+00:00",
      "modifiedDate": "2023-03-17T08:55:17.137+00:00"
    },
    {
      "@id": "d5331ddb-9f90-445f-9e86-8a7d87d3857f",
      "id": 34247,
      "hardwareId": "6ae5010e-1c27-4869-8679-be99ba3ced92",
      "user": "e4771618-9f1d-402c",
      "expirationDate": "2023-01-24T23:59:59.237+00:00",
      "maintenanceDate": "2023-01-24T23:59:59.237+00:00",
      "enabled": true,
      "productProfile": "fdd4536d-fb5f",
      "profileRole": "2c79ef63-bd3c",
      "createdDate": "2022-11-25T07:30:44.517+00:00",
      "modifiedDate": "2023-03-17T08:55:17.137+00:00"
    },
    {
  "@id": "baa20043-49e0-41a3",
  "id": 34453,
  "hardwareId": "2432ef7a-ada4-4357-812d-6b0bbe90ed6f",
  "user": "e4771618-9f1d",
  "expirationDate": "2023-05-16T23:59:59.027+00:00",
  "maintenanceDate": "2023-05-16T23:59:59.027+00:00",
  "enabled": true,
  "productProfile": "490a57be-0904-43ff-adaf-",
  "profileRole": "3da6da45-fed5-4c36-b7d7-",
  "createdDate": "2023-03-09T06:14:32.560+00:00",
  "modifiedDate": "2023-03-17T08:55:17.137+00:00"
}
  ],
  "enabled": true,
  "deliveryNote": null
}

I have used below logic

        .check(jsonPath(s"$$.hardwareIds[?(@.hardwareId == '${hardwareId}')].${x}").saveAs("hardwareIdObj"))
        .check(jsonPath(s"$$.licenses[?(@.hardwareId == '${hardwareIdObj}')].expirationDate").saveAs("hardwareIdObj"))

Hi @anaghad,

I assume you read our tutorials and participate in Gatling Academy
So, you should be aware of saveAs.

It will store your hardwareId in session variable.

In your code, you are using scala or kotlin string interpolation, not gatling expression language.
I suggest that you use the new #{hardwareId} notation not to confuse with string interpolation.

Does that help?

Cheers!

Hi @sbrevet,
Thank you for responding.
As suggested by you, I have used saveAs.
But I am facing issue while using the session variable in the consecutive- check method
I need to utilize the value of @id from “hardwareIds” array and get value of “expirationDate” from licenses array where licenses.“hardwareId” == hardwareIds.@id

I suspect that your JsonPath expressions are incorrect.
Honestly, JsonPath syntax and ecosystem is a mess (explained here).
I’d recommend switching to JMESPath where you’d have consistent results between the online evaluator on the official website and the Java implementation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.