Repeat Scenario Functionality for typeahead search

Hi All,

I am trying to build a scenario for a typeahead search. The typeahead doesn’t kick in till 3 characters are typed. I have following code written for it.

val typeaheadparam = csv(“SearchTermUS.csv”)

val typeaheadservice = scenario(“Typeahead Service”)
.feed(typeaheadparam)
exec( session => {
repeat((session(“SearchTermUS”).as[String]).length() - 3,“Counter”) {
println(“Search Term : " + (session(“SearchTermUS”).as[String]))
println(“Search Term Length : " + (session(“SearchTermUS”).as[String]).length())
println(“Inside the Long Loop, Count Value : " + session(“Counter”).as[Int])
exec(http(“Typeahead Service”)
.get(””“http://search.abc.com/onestore/store/typeahead.json””")
.headers(common_header)
.queryParam(“term”,(session(“SearchTermUS”).as[String]).substring(0,session(“Counter”).as[Int]+3))
.queryParam(“lang_locale”,“en_US”)
.queryParam(“limit”,“4”)
.check(status.is(200))) }
// println( "Search with term : " + (session(“SearchTermUS”).as[String]).substring(0,session(“Counter”).as[Int] +3))
// pause(1)
session } )

The code does compile. The problem is when it is being executed using the following command
searchServiceScenario.typeaheadservice.inject(rampUsersPerSec(1) to(peakRPSScenario1) during (rampTime seconds), constantUsersPerSec(peakRPSScenario1) during(steadyTime seconds))

It goes in repeat loop but is not in the executing any request.

What’s wrong in the above code?

Regards,
Sanjaya

You can’t use Gatling DSL inside functions.
Gatling DSL components are builders that are only built once, when the Simulation is loaded.
So, what you’ve done just creates new builders at runtime and discard them, they’re not par of the scenario chain.
You have to pass functions:

repeat(session => session(“SearchTermUS”).as[String].length() - 3,“Counter”) {

Thanks Stephane,

I did try the above way. It is still not resulting in any request being sent to server. Below is the modified code

val typeaheadservice = scenario(“Typeahead Service”)
.feed(typeaheadparam)
repeat(session => session(“SearchTermUS”).as[String].length() - 3,“Counter”) {
exec(http(“Typeahead Service”)
.get(""“http://search.abc.com/onestore/store/typeahead.json”"")
.headers(common_header)
.queryParam(“callback”,“nike.gadget.OneNikeNav.typeAheadCallback”)
.queryParam(“term”,"""${SearchTermUS}.as[String].substring(0,session(“Counter”).as[Int]+3)""")
.queryParam(“lang_locale”,“en_US”)
.queryParam(“limit”,“4”)
.check(status.is(200)))
}

Regards,

Sanjaya

You’re missing a dot before the call to repeat :slight_smile:

Opps, thanks.

It’s now sending the request.

unfortunately it’s not the parameterization isn’t working. I tried below two ways to extract the value in query param.

.queryParam(“term”,"""${SearchTermUS}.as[String].substring(0,session(“Counter”).as[Int]+3)""")

  • Compiled fine, but not replacing the parameter value.

.queryParam(“term”,"""${SearchTermUS}""".substring(0,session(“Counter”).as[Int]+3)) - compile error - error: not found: value session

What am I missing here?

Thanks,

Sanjaya