scalatestingperformance-testinggatlingscala-gatling

how to get javascript variable value in GATLING


I have a response body and i need some spesific javascript value in that.(__processUniqueID) How i can do ?

Gatling 2.3.1 version

<script type="text/javascript">
var __processUniqueID = '06c199ab-**********';
var __isDocument = false;
var __isDMSDifference = false;
var __hasSanction = false;
</script>

I want to output "06c199ab-**********".


Solution

  • You can use a regular expression check:

    .exec(
      http("Get Javascript")
        .post("my/endpoint")
        .check(status.is(200))
        .check(regex("""var __processUniqueId = \'(.*)\';""").find.saveAs("my_value"))
    )
    

    This will parse the response body and save the matching group in the session under the key my_value.

    See the documentation: