Jmeter - HTTP request run one time when find out right result - csv

After i pass issue by modify condition in "while" in Jmeter - Stop reading CSV file after find out right item
Now i want to run "http request" one time only when i find out right product. Currently, number of "http request" is equal number of loop in while.
How can i run HTTP request one time?

not sure if I understand your question correctly but would not https://jmeter.apache.org/usermanual/component_reference.html#Once_Only_Controller help?
It is triggered only once per each thread. Usually used for logins.

I used "IF controller" in "While Controller" and resolve this issue.
While ("${Error}"=="Response Error")
CSV file (brandid,brandurl,producturl)
if ("${brandOfWH}"=="${brandid}")
-- Http request
-- -- BSF Preprocessor
-- -- Get "Error" extractor

Related

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

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

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

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.

How to change content of Post Body in JMeter HTTP Request

Please forgive my ignorance as I'm a jmeter noob. My webservice accepts JSON objects so I was able to write a rudimentary test where I create an HTTP Request with a JSON object in the "Post Body" portion of the http request.
Anyway, what I want to do is have the HTTP Request choose a different JSON object from a csv file or some other input mechanism so that I can randomize the types of queries that are being run during the load test. Is there a way to do this? The closest is probably using variables (section 4.11 in the user manual) but I have a feeling that's not how variables are used.
A second way I've theorized (although I haven't tried yet since I think the method above is easier) is to create a HTTP Request Default obj with a bunch of HTTP Requests with different JSON objects in them and then use a Random Controller to randomly go thru my multiple HTTP Requests on each pass.
If there's a third way, I'm all ears to learn how to use this tool. I'll continue to read and possibly experiment with plan B above. Thanks in advance for any help you can give me.
UPDATE: So I tried the second way and it seems to work. I had 3 different HTTP requests and the number of times each request gets hit varies from run to run. I still invite answers from the community since I'd like to see what the pros do for issues similar to mine.
You have partially answered your question yourself, by saying "csv file or". Here are the specifics.
You will have to use CSV data set config in your test plan to read data from CSV. In your post body, use the variables read from CSV.
Here is a screen cast showing how to use csv data set config.

flex, multi request from the command class, how to differentiate each response from results in command

I run into a question that asked by a flex interviewer:
If there are 2 requests from the command class, and when back end process the request, they may take different time(the first command may take longer time to process so that it returns after the response of the second request).so, in your result-handler of your how do you know which response is for which request?
Note: they are in the same command, and they are processed by the same result handler.