Showing posts with label Gatling. Show all posts
Showing posts with label Gatling. Show all posts

Wednesday, June 26, 2013

Assigning variable from response data in Gatling

In my load testing script i needed to take out a value from the response and use it in the rest of the requests. Here is how i did it ,

here is the code snippet of how to acquire the value. My intended value was of format number-number
which is solved using very simple regex (\d+-\d+) and saved is as a variable commandId.

.exec(http("viewRecordSearchForm")
     .get("/mySite/searchStuff/searchForm")
     .headers(headers_1)
     .check(regex("""<input type="hidden" name="commandId" value="(\d+-\d+)" id="commandId"/>""").saveAs("commandId"))
)

Later this variable was used as request parameter,

.exec(http("queryForStuff")
    .post("/mySite/searchDataUsingCommandIdAndDates")
    .headers(headers_2)
    .param("""startDate""", """03/03/2012""")
    .param("""endDate""", """03/31/2012""")
    .param("""commandId""", """${commandId}""")
    )