Jmeter and Json, extracting and using variables for another request - json

I'm new to JMeter and I'm probably missing something quite simple...
Note: I'm using a json add-on as well.
After making a request, I extract a value from the response. If I check the view results I'm able to see the correct value in the variable I created.
-Initial extraction of value-
-how I tried to use my new value for a new request-
If I try use the variable in another request, I receive an error because the variable is now the default value.
What am I doing incorrectly that makes the second post request to use the default value and not the value it captured (if I did that correctly).
Thanks

JSON Path Extractor is a Post Processor. It is not a Sampler. It should be the child element of the first request 'Create Order' in your test plan if you are going to extract from the 'Create Order' response. If it is in same level with other requests, the post processor will be executed for each and every samplers in the same level. That is why, You are able to see the value for the first time. Now Post processor tries to extract the value from the Debug Sampler as well. As Debug Sampler does not match your JSON extract condition, It sets the default value.

2 years later (March 2018), with Jmeter version 4.0, solution it's the same.
With the new interface, simply by dragging the json extractor on the http request, the json is limited to perform the extraction operation on it, maintaining the results.

Related

How to pass both parameter and JSON in one single HTTP request body with having JSON a variable [JMeter]

I have a similar but extended question for the below question.
How to pass parameter and json both in http request request body in jmeter??
I will take the same example as mentioned in the above question/link.
Have to pass multiple parameters,
UserId=47
meeting={
"DeviceID":${deviceID},
"NetworkCarrierName":"VODAFONEIN",
"BatteryValue":"22",
"AppVersion":"1.1.3",
}
As you can see, DeviceID have a value from variable deviceID. I want to pass all these parameters and JSON in one single http request body.
What would be the approach for this?
In parameter I have to add the variable for value part for whichever key I want to refer to. It will work fine.
This image shows that..
The same approach will work fine, you can use JMeter Variables anywhere in your test plan, if there is a User Defined Variable or a pre-defined variable or a variable coming from a Post-Processor - JMeter will substitute the variable placeholder with its respective value in the runtime:
If you're uncertain regarding how to properly build your request the easiest is just recording it using HTTP(S) Test Script Recorder

trying to pass the value (which is extracted from json path extractor) to the next http request

I have extracted 10 values from a Json path extractor, naming device_1,device_2,device_3 to device_10. I am able to see these 10 values in debug sampler and now i want to pass on these value to the next http request one by one (may be by using a loop) but i am not able to find any way where i can pass all these 10 values one by one to next http request. As of now i am sending only 1st value as ${device_1} in the http request but i want 10 different users to access all 10 values one by one.
I believe ForEach Controller is something you're looking for.
Configure it like:
and use ${device} in the HTTP Request sampler which is inside the ForEach Controller.
The HTTP Request will be executed as many times as there are matches generated by the JSON Extractor.
The similar concept is described in Using Regular Expressions in JMeter article

Extracting value from Json response of POST request in Jmeter using Json Extractor

Post request Json Extractor Get request debug sampler error message I'm using Jmeter for stress testing of my application. Test plan that I'm building has a POST request which creates a user and the next PATCH request updates it. Basically I want to extract user_id from Json response received after POST request and add that id in the body of the next request. For that I use Json extractor in my POST request and when I check Debug Sampler the value is successfully stored. But when I try to use extracted user_id in any subsequent requests of the same thread it is not recognized. However when I tried to extract user_id of already created user with GET request then this user_id is normally recognized by other requests. I'm not sure whether Json extractor is not normally used with POST requests or I'm doing something wrong.
It's impossible to provide an answer without seeing the screenshot of your Test Plan or even better Schematic View (the option is available under "Tools" main menu entry since JMeter 5.1)
Given you're able to see the extracted value in the debug sampler I can think of 2 possible options:
Your syntax of referring the user_id variable is wrong, in JMeter the Variables are accessed like ${user_id}
Placement of your JSON Extractor is wrong, i.e. instead of putting it as a child of a specific sampler you have it at the same level as all Samplers therefore it's getting applied to the Debug Sampler as well and the extracted value gets overwritten. See Scoping Rules user manual section for more information

Variable is only set by JSON Post Processor with Debug Sampler enabled

I definitely feel like I am missing something obvious, but here it goes anyway. I have a script that does the following per user in a thread group:
login
get a json list for that user
extract a part of the list from the response with a regex extractor into a variable called feed
start a for loop with feed_matchNr number of iterations
start a Counter
get the nth item from the list and use JSON Post Processor on the feed variable to get an id
make an additional http request with that id
continue loop
This all works as expected ... until I disable the Debug Sampler. Then the http request no longer "expands" the variable, instead the request has something like /api/path/${myid}/foo and fails. What black magic is the Debug Sampler doing and how can I do the same magic without it?
Your issue is the following:
First understand that Post Processor only runs IF the is a Sampler in its scope:
http://jmeter.apache.org/usermanual/component_reference.html#postprocessors
So in you plan, when you put a Debug Sampler , it runs. If you disable it, it only runs for post comment, so it has not initialized the variable for post comment.
Also is there a reason to put -1 in JSON Post Processor, this means you want to get all values:
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Path_PostProcessor

JBPM rest calls with JSON

We want to start a process in JBPM6 using the rest API. We need to pass an object as a process variable.
We know how to do it JAXB and the execute call. But we want to do it with JSON and /runtime/{deploymentId}/process/{processDefId}/start
Is it possible? we try and have no success.
I am not sure whether my answer exactly addresses the question. But for someones use in future I place couple of lines here.
If you want to set a process variable when starting a process using the RESTful API, you can do it like this.
If your variable name is myVar just add the value as a URL parameter by appending the phrase "map_" to the parameter name. It means the parameter name should now be map_myVar. For an example see below request.
http://<host>:<port>/jbpm-console/rest/runtime/{deploymentId}/process/{processDefId}/start?map_myVar=myValue
You can confirm whether the value is set by writing below code in a script task.
Object var = kcontext.getVariable("myVar");
System.out.println("myVar : " + var);
See the 17.1.1.3. Map query parameters section of JBPM6 documentation.
After talking to the dev that is responsible for the REST API. I was able to confirm how it works.
The
/runtime/{deploymentId}/process/{processDefId}/start
Is a POST request where all the contents in the payload are ignored. The variables are written as key=value in the GET string.
With deployment id: com.web:work:1.0
With processDefId: work.worload
2 variables: var1 and var2
For example:
/runtime/com.web:work:1.0/process/work.worload/start?var1=a&var2=b
I'm still after trying to understand how to define objects with the remote API.
Meanwhile, I also confirmed that it is impossible to define objects using this way. The only way to define objects is only by using the JaxB. This uses the "/execute" path