How to make Jmeter use each login only once - jmeter

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.

Related

How to handle multiple tokens in a same thread group

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

How to perform JMETER Multiple threads doing multiple actions?

I have an requirement of creating test plan in jmeter
User 1 ==> 10 threads ==> 1st thread login into a GUI and edit 1st line , 2nd thread will edit 2nd line and so on till 5th thread for 5th line again same scenario continues till it reaches 10 thread.
How do we use CSV or parameterized concept to answer above use case?
There is no need to use any external parameterization like CSV files for this.
JMeter provides __threadNum() function which returns the current thread (virtual user) number so if you want 1st user to edit the 1st line - just use ${__threadNum} function in the place where you need to provide the line number and that would be it.
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

How do we run multi concurrent sessions Websocket testing using JMeter?

I was using the JMeter WebSocket Samplers to perform WebSocket latency testing. My test plan contains 4 thread groups.
Firstly, here is the order of operations I was producing, each step is grouped in a thread group. And the connection for the 1st. operation on Presenter was cached before executing the 2nd. operation because the 3rd. operation, the same Presenter, is gonna continue to use this connection.
def connection = sampler.threadLocalCachedConnection
props.put('presenterConnection', connection.get())
Same idea for the 2nd & 4th connection for Participant. The participant at step 4 is gonna continue to use the connection created at step 2.
Presenter connects to WS, creates session & saves the session id
Participant connects to WS & subscribes to the saved session
Presenter sends out commands
Participant reads the commands that were sent by Presenter
It worked as expected with single session. However I ran into an issue with the WebSocket Single Read Sampler at the 4th operation of reading commands that were sent from Presenter when I was running 2 concurrent sessions.
I changed the "Number of Threads" to 2 in the thread properties of each thread group. The presenter was able to create 2 session IDs at the 1st. operation. And I added the "Inter-Thread Communication PostProcessor" to store the session IDs in a queue such that it's able to be passed to other thread group. It worked for the first 3 operations until it went to the WebSocket Single Read Sampler in the last operation of reading the commands that were sent from the Presenter.
I had a JSR223 PreProcessor in place to use the cached connection at step 2.
def connection = props.get('Participant1Connection')
sampler.threadLocalCachedConnection.set(connection)
The issue was found in the response body of the 2 threads of the last operation. The first session ID was not being used. The first user at step 4 was using the 2nd session ID and the 2nd response body was empty because the 2 users were using the same session. What shall I do to fix this issue to have 2 users reading data from 2 sessions created accordingly?
This is something which normally happens when people copypaste the code without understanding what it is doing. Moreover if you need to pass data between thread groups most probably there is a problem with your test design.
Whatever.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
So when you have > 1 thread (virtual user) the second thread overwrites the value of the presenterConnection property so no matter how many threads you have they all are trying to use single instance of the presenterConnection
My expectation is that you want a connection per thread, in this case you should add current thread number as a prefix/postfix for the property key so:
1st thread would use presenterConnection1
2nd thread would use presenterConnection2
etc.
Amendment to "your" code would be something like:
props.put('presenterConnection' + ctx.getThreadNum(), connection.get())
similarly for accessing the connection.
In the above example ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands available for the JSR223 Test Elements.

Multiple user login in JMeter

I am trying to perform load testing on NodeJS application, the application allows single login session for an user.
But, when i tried to perform load testing with 8 concurrent users (using the same credentials) it was working.
So, i tried to create 10 user IDs and added to the CSV file and configured "CSV Data Set Config" and "HTTP Cookie Manager" and set the "Number of Threads" to 80.
When I run the test plan, the credentials are not passed to each sessions equally. for example, userID1 is passed 3 times and userID2 is passed 7 times.
Can you clarify the reason for this behaviour and how to run the threads with each credentials (8 sessions for every credentials) from csv file ?
Make sure you have set the options for CSV Data Set Config as All Threads for Sharing mode and provide a minimum ramp-up period (say 1 second) so that each thread reads the CSV lines properly without clashes.
For the question why it worked 8 concurrent sessions , where you allow only single session from UI - My guess is you used the same credentials for all 8 users - so server might have considered it to be 8 parallel requests from the same user. It depends on how session is maintained. For eg., if it was with a session-cookie , then If you had 8 different cookies it might have failed. But this is only a guess, as I don't know how its done in your app.
JMeter acts as follows:
All threads are started within the bounds of the ramp-up period which you define in the Thread Group
Each thread starts executing Samplers upside down (or according to the Logic Controllers) as fast as it can
JMeter waits for previous request to finish before starting next Sampler
When the thread doesn't have any more Samplers to execute and loops to iterate - it's being shut down
If you observe the situation when this or that logic was used more than another, most probably the response time for the login was less.
You might want to check the size of the response as for successful requests it should be more or less the same and it might be the situation when the server returns HTTP Status code 200 but response body contains errors, to wit some logins may fail silently, if this is the case it makes sense to add a Response Assertion to add some extra checks, i.e. presence of "Welcome" text or "Logout" link or absence of "error" text or whatever.
What i could understand is you are trying to achieve 8 session each user.in order to do that you have to make 10 concurrent threads and 8 iterations that is how you will achieve 8 session for every credentials.
But of your requirement is to run 80 concurrent users then try to make 80 users and run the test.

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