# Repeat Scenario Functionality for typeahead search

**URL:** <https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675>\
**Category:** Gatling (Open-Source)\
**Created:** [November 21, 2015, 1:17am UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675 "2015-11-21T01:17:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjaya\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sanjaya\_Kapoor](https://community.gatling.io/u/Sanjaya_Kapoor)\
**Post date:** [November 21, 2015, 1:17am UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675/1 "2015-11-21T01:17:30Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 21, 2015, 7:47am UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675/2 "2015-11-21T07:47:09Z")

</div>

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”) {

---

<div class="post-metadata">

**Author:** ![Sanjaya\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sanjaya\_Kapoor](https://community.gatling.io/u/Sanjaya_Kapoor)\
**Post date:** [November 23, 2015, 6:40pm UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675/3 "2015-11-23T18:40:54Z")

</div>

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](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](http://status.is)(200)))  
}

Regards,

Sanjaya

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [November 23, 2015, 6:56pm UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675/4 "2015-11-23T18:56:32Z")

</div>

You’re missing a dot before the call to repeat 🙂

---

<div class="post-metadata">

**Author:** ![Sanjaya\_Kapoor](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sanjaya\_Kapoor](https://community.gatling.io/u/Sanjaya_Kapoor)\
**Post date:** [November 23, 2015, 7:08pm UTC](https://community.gatling.io/t/repeat-scenario-functionality-for-typeahead-search/2675/5 "2015-11-23T19:08:57Z")

</div>

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
