I have one endpoint which will return response in below format:
{
“items”:[ { …}],
“nextPage”:27ubdkj
}
If “items” array length is within 10, then “nextPage” value will be null.
{
“items”:[ { …}],
“nextPage”:null
}
In gatling script, I am extracting the “nextPage” value using check method:
.check(jsonPath(“$.nextPage”).optional.saveAs(“basicNextPage”))
And, in my scenario, I have do while loop asserting whether “nextPage” value is exists or not and based on that executing another request:
exec(getAllEntitlements)
.doWhile(“${basicNextPage.exists()}”) {
exec(getAllEntitlementsAndPage)
}
While running this script, I am getting error “[ERROR] i.g.h.a.HttpRequestAction - ‘httpRequest-33’ failed to execute: Attribute basicNextPage’s value is null”.
Beware that exists() only checks for the existence of the key, even if the value is null.
You probably have to write a more complex test condition with the Session API.
I tried having a query like this : doWhile(session => session("basicNextPage").asOption[String].isDefined) and asLongAs(session => session("basicNextPage").asOption[String].isDefined)
But still getting same error “[ERROR] i.g.h.a.HttpRequestAction - ‘httpRequest-33’ failed to execute: Attribute basicNextPage’s value is null”.
Can you provide me some example to fix this issue?
I have used the above condition, but still facing the error Condition evaluation crashed with message 'j.l.ClassCastException: Attribute basicNextPage's value is null', exiting loop
I have provided the httprequestbuilder which I have been using:
val getAllEntitlements: HttpRequestBuilder = getEntitlementByAccount("entitlement_GetAllEntitlements","")
.check(jsonPath("$.items").notNull)
.check(status is 200)
.check(jsonPath("$.nextPage").optional.saveAs("basicNextPage"))
val getAllEntitlementsAndPage: HttpRequestBuilder = getEntitlementByAccount("entitlement_GetAllEntitlementsAndPage","page=${basicNextPage}")
.check(jsonPath("$.items").notNull)
.check(status is 200)
.check(jsonPath("$.nextPage").optional.saveAs("basicNextPage"))
Also provide the scenario in which way I have constructed calling APIs: