Predictive search simulation - as User types in Search term, Browser sends search requests repeatedly

Hello Gatling experts,

Could you please advise how to perform following simulation.

As user types in search word, Browser Sends search request and shows possible search terms.
eg: when user tries to type housing, following search requests are sent to the server

  1. /service/search/ac?q=hou
  2. /service/search/ac?q=hous
  3. /service/search/ac?q=housi
  4. /service/search/ac?q=housin
  5. /service/search/ac?q=housing

I am trying to create simulation for this scenario.

.feed(feeder)
.group(“Search from home page”){

exec(http(“request_28”)
//.get("/service/search/ac?q=hou")
.get("/service/search/ac")
.queryParam( “”“q”"", “${searchCriterion}.dropRight(2)”) ===> My intention is to perform search using Search term with last 2 chars truncated. This is not working. Instead search performed with “SearchCritera + dropRight(2)” string"
// .queryParam( “”“q”"", "${searchCriterion}"dropRight(2)) ====> This approach giving compile error
.headers(headers_28)
.resources(
http(“request_29”)
//.get(uri4 + “/service/search/ac?q=housi”)
.get(uri4 + “/service/search/ac”)
.queryParam( “”“q”"", “${searchCriterion}.dropRight(1)”)
.headers(headers_28),
http(“request_30”)
// .get(uri4 + “/service/search/ac?q=housing”)
.get(uri4 + “/service/search/ac”)
.queryParam(""“q”"", “${searchCriterion}”)
.headers(headers_28),
http(“request_32”)

.get(uri4 + “/search?q=${searchCriterion}&cat=sitesearch”) ==> This is working
.headers(headers_0)
.check(regex("""

  • ****<a href="([^"]+)">${searchResult}""").saveAs(“computerURL”))) // This is not working.
    }

    Please could you also advise how to select first search result, using regular expression. search results listed for following search results




    1. Apply for housing


      Find a place to live with a council or registered social landlord.







    2. Emergency housing if you’re homeless


      Find out your options if you’re homeless and don’t have anywhere to stay tonight.




    Thanks in advance.

    Regards,
    Raja

  • You can’t write any code you want in Gatling EL.
    You’ll have to write a function so you can use dropRight or substring: gatling.io/docs/2.1.6/session/expression_el.html#expression