Search code examples
performance-testinggatlingscala-gatling

how to extract token generated by js script (challenge.flood.io)


I am currently studying Gatling for performance testing, I am new to both. Making the task, I have stuck on the step when I need to get a token to pass it to parameter to get to the other page. The difficulty for me is that the token is absent in the body, it is generated by a script, so I cannot get it with ...check(css(... or check(regex(...

enter image description here

I tryed to get the token by css and regex, getting empty result

.exec(
  http("Step 5 page")
    .get("${redirection}")
    .check(status.is(200))
    .check(substring("Step 5"))
    .check(css("input[name='challenger[step_id]']", "value").find.saveAs("step_id"))
    .check(css("input[name='challenger[step_number]']", "value").find.saveAs("step_number"))
    .check(css("input[name='commit']", "value").find.saveAs("commit"))
    .check(css("span.token").find.saveAs("one_time_token")))

How can I get the token?


Solution

  • It's pretty clear from this code that this page is performing an extra ajax request to the /code url to fetch the token and then display it in the page.

    You'll find the value in there (you can see this HTTP request a few lines below in the Network tab).

    Note: in order to learn Gatling you should probably check the Gatling Academy.