JMeter variable scope in threads - jmeter

I have a JMeter tests which does the following:
It makes a GET request. The request returns some ID which is extracted by a Regular Expression Extractor and is set to a variable myId.
Another GET request is made using this ID stored in myId. It is important that the same ID is used as returned by the request before. Not any other ID!
This simple scenario works fine. But when I increase the "Number of Threads (users)" from 1 to (let's say) 5, I run into concurrency problems:
Thread 1 makes the GET request and assigns the ID to myId.
Thread 2 makes the GET request and assigns the ID to myId.
Now thread 1 runs again and makes the second GET request but with the wrong ID as thread 2 has changed it. Now everything breaks.
How can I avoid this?

As you use the same name for the reference myId, if in the second extraction it doesn't find anything then myId will contain the previous extracted value.
What you can do to check this, is to put in Default Value field:
nv_myId
as per:
http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor
You can use a Debug Sampler to show content of variables

Related

How to save 10 different id from Jmeter response and use it in next 10 requests

I am currently running 10 different threads like this:
each of the thread response will provide a different id in the response and i want to save them and use it as a request in the next test case(10 threads) so there will be 10 ids and 10 threads and each thread will have a unique id as a request. This is what I am doing:
Here is the first request
This is how I am extracting the values
This is how i am using the final request however i am not able to get the desired results
UPDATE:
I tried Dmitri Answer but still no luck i am extracting the id by using this
I used __threadNum() function as the prefix or postfix for the property name like:
${__setProperty(loginassistant_${__threadNum},${loginassistant_},)}
and read it similarly:
${__P(loginassistant_${__threadNum},)}
but it is not working and it is setting the value as a static string(see screenshot below):
This is how and where i am defining my loginassistant using the simple controller:
You're using properties which are global, if you have more than one thread the next thread will overwrite the property defined by the previous thread so it could be mismatch.
If you don't need to pass values across thread groups - go for JMeter Variables instead, variables are local to the thread (virtual user) and the properties are global for the whole JMeter/JVM instance
If you do need to pass values across thread groups - either use __threadNum() function as the prefix or postfix for the property name like:
${__setProperty(loginassistant_${__threadNum},${loginassistant},)}
and read it similarly:
${__P(loginassistant_${__threadNum},)}
or go for Inter-Thread Communication Plugin

Value cannot be null: Parameter: Source error received from JMeter

I have been receiving this error message on particular request - "Value cannot be null. Parameter name: source".
My Scenario is that 1 user will be transacting 5 transaction (Search and Remit). I'm targeting to run 650 Users to 3250 Transaction. The problem is that one particular request which is getting details from the DB, some data is passed but mostly are the mentioned error message above.
I Have 2 CSV Config, 1 from Users, the 2nd is for the Data where the second csv is inside the Loop Controller.
Your application tells you that the request is not correct, it expects a value and you're failing to provide the value. Use Debug Sampler and View Results Tree listener combination to validate the values of the JMeter Variables which are being sent for successful and not successful requests, it might be a test data issue, for example an extra comma in the CSV file will make CSV Data Set config "think" that this is the delimiter for the next column.

TO check response of particular id should be diff through jmeter

MY response for api is:-
"data":{"shortId":"lu131559"}}
Now i wants to check short id is different for every virtual user.
mns if second hit gone response data is
lu131560
So i want to validate that after 1000 request from virtual user every time i am getting diff id.
If you know the "current" value of the shortId and expect it to be incremented by 1 each time you call your API you can go for Response Assertion and use __intSum() and __counter() functions combination in the pattern like:
lu${__intSum(131559,${__counter(,)},)}
Each time the Assertion will be called it will expect the value to be incremented by one, i.e.
lu131560 - for 1st user or iteration
lu131561 - for 2nd user or iteration
lu131562 - for 3rd user or iteration
etc.
More information: Apache JMeter Functions - An Introduction

How to pass response body values from one thread to different threads by incrementing the values in the response body in JMETER

I just wanted to extract value from the response body of thread1(1st thread am running once by passing number of threads and loop count 1 each) and need to pass same for the 2nd thread(2nd thread am running multiple times by passing number of threads 10).
This is my response body from Thread1.
{"availablePhoneNumbers":["3052191421","3052192726","3052192566","3052195123","3052194493","3052199654","3052194684","3052199164","3052190020","3052190352"]}
i just wanted to pick the first data 3052191421 and wanted to run in thread2 for all the HTTP requests.
then 2nd data 3052192726
then 3rd data and so on.
Could you please get the solution for this?
Thanks in advance..
Extract first number from the response. This can be done using JSON Extractor configured like:
Names of created variables: number
JSON Path Expressions: $.availablePhoneNumbers[0]
Later on you will be able to use __longSum() function in order to:
add 1 to ${number} variable
return the value
save the result back into the ${number} variable
Demo:

JMeter - repeatedly run a While Controller

Goal:
I would like to visit 10 different URLs of the form http:localhost/path/item/${id} where id is a Random Variable. For each of these URLs, I want to request them until the response returns a specified string.
Current setup:
I have a While Controller with an Http Request under it. The condition looks like ${__javaScript('${response}'.indexOf("my string") == -1,)} (the response variable is saved via a JSON Extractor). I also have the Loop Count in the Thread Group set to 10.
Problem:
My test plan works fine, but only for one URL. It's as if it's ignoring the Loop Count setting. Assuming the While Controller makes two requests per URL, it's only making two requests total, rather than expected 20.
This is puzzling because if I use a Loop Controller with a Loop Count of 5, it makes 50 total requests.
How can I achieve the desired behavior?
Cannot be 100% sure without seeing the whole plan, but I suspect it's because you are not unsetting ${response} for next iteration, after it reaches true condition. I.e.
First iteration starts, and ${response} is empty/undefined ==> enters while
At some iteration within while it sets ${response} so, that ${__javaScript('${response}'.indexOf("my string") == -1,)} gives true ==> While exits
Next iteration starts. If at this point ${response} is still the same as in previous iteration, it will never enter while, since it's already true.
If this is the case, reset value at the beginning of iteration.
To reset the value, add a BeanShell Sampler nd either remove a variable:
vars.remove("response");
or set its value to empty / something else:
vars.put("response", "");
If this is not the problem, look for exceptions in the jmeter.log. Could be that your script is exiting due to error.

Resources