Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes - json

I am now using Jmeter to run the test of APIs.
The situation is that I have a login Api which will return a token inside response. I use a JSON extractor to save the token as a variable. Then, I use the ${token} is the header of other requests.
However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.
Therefore, may I ask is there any method to solve it and why?
Thanks very much.

Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.
There are following options:
If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
and when you run your test next time the .jtl results file will contain response bodies for all the requests.
Another option is using a Listener like Simple Data Writer configured like:
and when you run the test the responses.xml file will contain the response data
Both .jtl results file and responses.xml can be inspected using View Results Tree listener
More information: How to Save Response Data in JMeter

Related

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

Azure Logic Apps - Verify content in JSON file

I have a logic app that runs as follows:
Step 1 = Recurrence (the schedule for the logic app to run)
Step 2 = HTTP (Performing a POST call on a custom API that returns a JSON file)
Step 3 = Create Blob (which uploads said document from Step 2 and uploads it to blob storage)
What I would like to do now is add an extra step between Step 2 and Step 3. After making the HTTP POST call, I would like to verify the content inside the JSON file that gets returned. If there is an error present in the JSON file, I want the Logic App to stop there.
Is there a particular step that I can use in Azure's Logic App to verify the data and have that step decide if it should continue on or not.
For this requirement, you can refer to my logic app below:
1. I initialize a variable named "resultFromHTTP" to simulate the json from your HTTP request(step 2). And I delete some character, so the "resultFromHTTP" is not a valid json format.
2. Then I initialize another variable and use the expression json(variables('resultFromHTTP')) in its value.
3. Run the logic app, it will fail and show error message like below screenshot. If the json is in valid format, it will run success.
===============================Update==============================
For your latest question, if the result json from HTTP request is not in valid json format and not a very long string, you can do it like this:
The contains(... expression is contains(variables('resultFromHTTP'), 'Data Not Found'). Then you can do what you want under "if true" or "if false".
If the result json from HTTP request is in valid json format, you can use "Parse JSON" action to parse it and get the specified field and then judge if it equals to "Data Not Found".

Unable to capture request and response values into csv by using sample variables

Could some one please advise me where am i doing wrong.
When i tried to capture request and response values into csv using sample variables by adding in the next line to user.properties file: sample_variables=request,response
it's throwing null in the request and response columns in the csv file.
Is there is any another work around to achieve this?
Thanks,
Rajani
Please follow the below steps to capture the request URL and response. Alternatively, you can extract the request/response using Bean Shell sampler.
Open JMeter.Properties and configure the sample variables. Restart JMeter.
In your test plan, create two Regular Expression Extractors for your HTTP request, one is to capture 'request' and another is to capture the 'response'. Use (?s)(^.*) regular expression to extract everything.
To capture the request, configure as shown below. If you want to capture the request headers, select Request Headers radio button.
To capture the response, configure as shown below.
In the Aggregate report, make sure you checked the options as shown below and provide a name in Filename e.g. google.csv.
Here is my JMeter test plan for Google.com
Here is the expected output. Check in the JMETER_HOME\bin\google.csv.

Jmeter CSV data config element not working

I have created jmeter script for load testing and added CSV data element to read Username and Password of 300 Users.Also followed below steps;
Created CSV file using a notepad and stored it in a directory where created script stored.
Defined variables and file path in CSV data set element
Used variables as parameters of HTTP request
Increased number of Threads
But it doesn't worked as expected.How can i fix this?
Temporary reduce threads count to 1-2, add View Results Tree listener and inspect request and response details.
If don't see proper username/password combination in the request body - your script is misconfigured. Check out Using CSV DATA SET CONFIG guide for detailed setup instructions.
If you see valid username/password pair but login is not successful, follow below checklist:
Add HTTP Cookie Manager to your test plan
If point 1 doesn't help - check for dynamic request parameters. Probably you'll need to extract some value from the first response (when you execute GET request for the login page) with the Regular Expression Extractor, convert it into a JMeter Variable and add it as a parameter to the request which performs login.

How to use responses from a Jmeter JDBC Request in a HTTP Request

Here's my situation:
I want to do this:
I have a list of URLs in a MySQL database which I want to hit using a HTTP Request to see if the response is a HTTP Status code of 404 or not.
I have done this:
Added and configured a JDBC Config Element.
Added and configured a JDBC Request Sampler. Basically a select statement that returns a table with 8 columns. I have provided 8 comma-separated variables for the 'Variable names' field, so that the results of the JDBC request can be identified with these variable names.
Created a HTTP Request Sampler that uses one of those variables ${url} in the 'Server Name or IP' field.
Though the JDBC request works flawlessly and returns a table with a bunch of rows, the problem with this is that the HTTP Request Sampler never picks up the variable from the JDBC Request result.
The HTTP Request looks like this in the 'View Results Tree':
GET http://${url}/
I have tried these solutions:
Add 'Save Responses to a File' listener to the JDBC Request. This creates a file of type '.plain' and not a CSV. Had it been a CSV, I could have utilized that CSV file by creating a CSV Data Set Config. So this attempt failed.
I have tried forcing the file name in the above attempt to always use 'C:\JMETERTest\data.csv'. But it ends up creating a new file named 'C:\JMETERTest\data.csv1.plain'. This attempt failed too.
I tried to reference the URL column as ${url_1} in the HTTP Request's Server Name field. It worked. But the problem now is that in the results tree, all the requests are going for the the URL from only the first row of the result set. I see that this is because of the row number '_1' specified in the ${url_1} above. I can use this if someone can suggest a way to parameterize the '_1' into a variable that I can loop through (probably using a 'Counter' element). I created a Counter Config Element by the Reference Name 'loopCounter'. And used this in the Server Name field of the HTTP Request:
${url_("${loopCounter}")}
But now my HTTP Requests look lamer:
GET http://${url_("${loopCounter}")}/
This did not work too.
Solution 3 looks more doable to be only if I could resolve the parameterization of the row number.
I am open to JMeter Plugin suggestions too.
I will update anything else that I try as we go on.
P.S. Please let me know if my question is not clear in anyway.
Have you tried wrapping the HTTP sampler in a ForEach controller (parent) where the variable for the controller is the URL variable obtained from the JDBC sampler?
Also, the output variable in the ForEach will be the variable you now use in the HTTP sampler.
That way it will iterate through each variable from the beginning of the index to the end and run the sampler once each time.
In 'Save responses to a File' Listener, Select Checkboxes "Don't add Suffix and Prefix". Checking these two options will ensure, you get exact Log file name.