0
votes

In just starting to use JMeter I am trying to set variables of the form taskId_1, taskId_2, taskId_3 (defined in "User Defined Variables") and use them in HTTP Samples (REST requests). When I run postprocessors none of my JSON Extractors or Regular Expression Extractors save the values matched (and I tested the extracted regular expression using RegExp tester.)

The response sent from the GET request that I am parsing looks like (edited for readability):

{
    "case-data": {
        "Description": "100 parallel tasks",
        "Workflow": {
            "com.MyCompany": {
                "workflow-case-id": null,
                "stages": [
                    {
                        "stage-guid": "470D2E00-A9E1-11EB-887B-4226FC2CA371",
                        "tasks": [
                            {
                                "task-name": "Stage1Task1P",
                                "user-group-id": "Joe",
                                "task-id" : 52
                            },
                             {
                                "task-name": "Stage1Task2P",
                                "user-group-id": "Joe",
                                "task-id" : 73
                            },
                                                        {
                                "task-name": "Stage1Task3P",
                                "user-group-id": "Joe",
                                "task-id" : 123
                            }
                        ]
                    } ] }}}}

Following the BlazeMeter tutorials, for the Regular Expression Extractor I use

Apply To "Main sample and sub-samples"
Field to check "Response Message"
Name of created variable taskId
Regular expression task-id"\ :\ (.\d+)$
$1$

(I have also tried taskId_1 - my ideal solution would set all the taskId's at once).

For the JSON Extractor that I just tried I use:

Names of created variables: taskId
JSON Path Expressions: $."task-id"  (LOG ALL indicates Could not find JSON Path - so I will revise)
Match No: -1
Default Values: taskId not matched

It is as if none of these strings are ever matched so the values are not set - not even default values. I also have a Debug Sample, Debug Postprocessor and a View Results Tree included in the parent Logic Controller - but see no values of variables set anywhere (even in the logs).

I have other JSON extractors that attempt to traverse down the object tree from the top but they also are not setting my User Variables although LOG ALL indicates they are setting the variables of the same name.

  1. What is wrong with my match expressions and assignment parameters?
  2. How can I change my usage of Debug Sampler/Postprocessor/View Result Tree/Properties and variable viewer (which has JMeter variables = True) to observe variables?
    enter image description here
  3. Is there a way to run a test plan one step at a time (e.g., a preprocessor, a request, a postprocessor then another postprocessor) by clicking on UI elements?
1

1 Answers

1
votes
  1. Regular Expression Extractor:

    "task-id"\s*:\s*(\d+)
    

    enter image description here

    More information: JMeter Regular Expressions

  2. JSON Extractor:

    $..task-id
    

    enter image description here

    More information: Jayway JsonPath

  3. To view generated variables just add a Debug Sampler somewhere at the bottom of your script and add View Results Tree listener so Debug Sampler would be in its scope, see How to Debug your Apache JMeter Script for more details.