How to handle multiple tokens in a same thread group - jmeter

I have created two transaction controllers in a thread group which accesses same csv file. My goal is to scan and pass a barcode through 2 transaction controllers. If first transaction controller scans a barcode then the 2nd one should scan or pass a barcode as they are accessing the same csv file.
When I execute my script the first transaction controller successfully scans and pass the barcode but the 2nd transaction controller's APIs shows 401 error. If I use only 1 transaction controller (Any of 2) then it shows no error but I want that both should work.
In order to make work both transaction controller with separate tokens what approach I should follow?
Note :
Both Transaction Controllers uses separate token values. For my script I have passed the tokens from a separate csv file (Token1, Token 2)
All barcodes are stored in another csv file that means both transaction controllers are accessing same csv file and for only tokens the script is accessing a separate csv.
Scenario: Suppose, Transaction Controller 1 scans a barcode (let's say 10010) and passes it then the 2nd transaction controller should not throw any error and should scan same barcode.
My Observation:
In both transaction controller the token value is different, Eg - for first it is "XYZ==" and for 2nd it is "mkp!=". If I provide same token value in both transaction controller then the script works fine but if I provide separate token values then only 1 works and second fails.
Is there any solution by which I can manage multiple tokens in a single thread group?
Note: Tokens are passed in jmeter script by using separate csv file.
Please find the attached photo for further reference.Error

With default Sharing Mode of "All threads" JMeter will pick up the next line from the CSV on each iteration of each virtual user. If you want 2nd user to read the same value as 1st one - change Sharing Mode to "Current Thread"
Alternatively you can use __CSVRead() function where you decide when to proceed to the next line

Related

How to update the array values from existing based on the condition and again pass same array with updated array element

We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's scope.

Jmeter - How to stop While Controller once getting the expected values from Data Base?

I am trying to run the performance script which has API which takes the payload as file from S3 and submit to target system. After the request is completed I need to login to db and verify the status of the transaction. Here there is delay in getting inserted to db which is fast for payload with small file size. As I started submitting large files 1 GB to 15 GB, there will be delay in inserting a table.
So the JDBC request which has modified_date will be "null" and Status will be "null" for large payload when request is new. I have used constant timer but not sure how long it takes to insert in table. Is there any way I can make jdbc request to wait till i get result for modified_date will be "2021-02-10 18:17:44.538" and status will be "message deliver" for message table.
1)How to make loop keep on running till both the values inserting in the message table ?
2)How to stop while controller once I getting the expected values for modified_date and status ?
While Controller is being executed until the condition is met
You can combine more than one condition if the function allows it, the most powerful is probably __groovy()
Example condition:
${__groovy((vars.get('Status') != 'message deliver' || vars.get('modified_date') == 'null'),)}
Demo:
In the above example vars stands for JMeterVariables class intance which provides read/write access to all JMeter Variables in current context. See the JavaDoc for all available functions. You might also be interested in Top 8 JMeter Java Classes You Should Be Using with Groovy article which provides more information on JMeter API shortcuts available to JSR223 Test Elements and __groovy() function

How to make Jmeter use each login only once

I am writing a JMeter webdriver test for 8 concurrent users.
In my test, I created a CSV Data Set Config with 10 logins.
I have noticed that JMeter is reusing the same login for at least 2 users.
This causes an issue where the 2 logins are trying to do the same task and one of them will fail waiting for specific elements to appear.
Is there a way to force JMeter to always use an unique login per user?
It depends on the nature of your test and how you set up the CSV Data Set Config.
If you set "Sharing Mode" to All Threads - each thread will be reading new value on each iteration:
however if you will have more than 1 iteration:
1st user will read line # 9
2nd user will read line # 10
3rd user will read line #1
If you want to have "unique" data consider the following approaches:
Using __CSVRead() or __groovy() function to read the data from file, this way you will have control on when to proceed to the next line
Using HTTP Simple Table Server which "READ" endpoint has KEEP=FALSE parameter so once data is used it is removed so no other thread can use it.

Jmeter - running multiple threads using different author token

I have created a thread with three steps to:
Access token request: it generates a token to be used in step three. This token is stored in a property
${__setProperty(accessToken,${accessToken})}
Logon Get request to hit a url
Logon Post request, pass some data to the url and I have set the Authorisation header using the Bearer + accessToken (the one generated in first step.
Running a single thread it works, perfect; but when I increase the number of threads, the 3 steps are not running in sequence, maybe I have some Access token before the first Logon Post and I see the token this one is using is not the token generated in the first step, it is the last one generated.
If I set a rump time longer of the total execution time it works, but then I cannot run several threads on parallel.
How can I configure the script to run the threads using the correspondent token generated in step 1 in each Post? How can I different properties or variables to store the token of every thread and use them?
Thanks.
Your issue is that you are mixing Variables and Properties.
In summary, as per functions reference:
Variables are per Thread
Properties are shared accross Threads
So don't use setProperty, just use ${accessToken}
Use property only when you want to effect all threads. Otherwise you can save variables in other variable as in User_Parameters where you put new variable name the value can be a different variable as ${accessToken}
filling in the Variable name in the 'Name:' column. To add a new value to the series, click the 'Add User' button and fill in the desired value in the newly added column.
Values can be accessed in any test component in the same thread group, using the function syntax: ${variable}.

Clarification on Regular expression Extractor and CSV Data set config

Question 1 ) I am reading user credentials from a CSV file and trying to simulate concurrent 3 user login scenario like below.
My csv file data is like below, each in a new row. The problem now im facing is all requests are useing credential_001 if I use Attached ( thread group Settings .JPG) thread group settings. but if I make it to loop count 3, then it sends login requests for 3 users. What is wrong in my approach. please advice
credential_001
credential_002
credential_003
[http://i.imgur.com/FNXTMvA.jpg][1]
Question 2 ) When I capture 3 session tokens in first authentication cycle, I wand to use that 3 requests in next 3 requests. How can I do this ? is it posible to do like this. with my current approach it is always send the session token of first authentication in later http samplers.
[http://i.imgur.com/vhJrGt3.jpg][2]
below is the regular exp extra im using , and Im using ${SessionGuid} in later http sampler
Question 1
Consider switching to __CSVRead() function as CSV Data Set config switches to next row on next iteration, not on next thread. Example CSVRead configuration will look like:
${__CSVRead(/path/to/file/with/credentials.csv,0)
Question 2
Consider using __threadNum() function together with ${SessionGuid} variable, this way you'll be able to get
SessionGuid1 for the first thread
SessionGuid2 for the second thread
You can evaluate SessionGuid1, SessionGuid2, etc. variables using __V() function as follows:
${__V(SessionGuid${__threadNum})}
For extended information on above and more functions check out How to Use JMeter Functions post series.

Resources