Reputation: 1
I am working on a performance testing for an E2E scenario and There are 9 chain of requests.
In this 9 chain of request, I have two diff set of baseUrl.
Request1: baseUrl1/someUrlPath Request2: baseUrl2/someUrlPath Request3: baseUrl1/someUrlPath Request4: baseUrl1/someUrlPath Request5: baseUrl1/someUrlPath Request6: baseUrl2/someUrlPath . . . Request9: baseUrl1/someUrlPath
Each request is heavily dependent on the test data of previous request's response ( be it response session , some of the response value etc)
How to implement this E2E user journey in gatling scala?
Problems I am facing:
If I am trying to build it in a single simulation class in gatling scala, two different base Url can not be mapped with one httpProtocol
If I build separate httpProtocol, like below:
setUp( scn.inject(atOnceUsers(1)).protocols(httpProtocol), scn1.inject(atOnceUsers(1)).protocols(httpProtocolSim) ) then I can not transfer the values from a method A used in httpProtocol to another method B httpProtocolSim in the chain (as different session in different protocol)
Please let me know if anyone has any strategy or workaround.
Upvotes: 0
Views: 132
Reputation: 2545
If you have a multiply base urls the best way is to provide an absolute path for each requests.
Instead of:
http("...")
.get("/questions")
You ought to write a full path, which includes the protocol and, essentially, the base URL:
http("...")
.get("https://stackoverflow.com/questions/")
Perhaps, in your scenario, a single base URL predominates. You could define it using http.baseUrl(...)
and utilize a relative path in requests. However, for other base URLs, employ a full path."
Upvotes: 0
Reputation: 54
Let's say you have a response with this json Body:
{
"Param1":{
"ParA": "rand_value"
}
}
As Gatling's document stated here you can perform a check and then extract a value as you want in response, a sample code written in Scala is below
exec(
http("name")
.post("your target URL")
.body(StringBody("""{your body here}"""))
.check(jsonPath("$.Param1.ParA").saveAs("yourVarNameURL"))
)
As the code block above, a request has been made with a validation check and extract was performed, thus the value is saved in virtual user session as "yourVarName" (holds rand_value
). To understand more about virtual user session, see here.
When you successfully extract the value, and you want to pass that into next request, simply put as:
exec(
http("nameRequest")
.post("#{yourVarNameURL}") //you passed the value rand_value in here
.body(StringBody("""{your body here}"""))
)
In this step, you called to VU session variable by using Gatling's EL #{yourVarName}
note that this is different from language's string interpolation ${}
, though they have the same effect. Then voila, you successfully passed the value into next action.
All these action are under one .protocols(httpconf)
, so when you say about Map
, I am not sure what exactly your code block looks like to help further.
Return to your question:
If I am trying to build it in a single simulation class in gatling scala, two different base Url can not be mapped with one httpProtocol.
>>> you can have two different base URL with one httpProtocol, as shown in example above and in gatling's document.
Hope this help.
Upvotes: -1