Clarification on Regular expression Extractor and CSV Data set config - jmeter

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.

Related

Jmeter - How to pass multiple tokens from http login request to another http request

I am currently designing a test case for multiple users testing using jmeter and I kind of need some help.
Here's the scenario:
Suppose I have 2 different login portals with 500 different users on each portal. I want to do login, access getExamSchedule, startExam, getListQuestion, getOneQuestion, submitOneQuestion and finishExam so I create one new thread group for each request. Each thread has 2 samplers (1 for portal A, 2 for portal B).
My question is how am I supposed to pass the multiple generated tokens from login thread so that I can access the rest of the thread with different tokens. And also each http request has some response I need to extract to be used on another thread. I tried to extract the tokens and the responses to csv file but somehow it didn't work. Let me know if there's any best practice for this scenario. Thank you in advance!
so I create one new thread group for each request - normally you should create separate/different Thread Groups only for new logical groups of virtual users, for your use case I think everything could be in one Thread Group.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you really need to pass values across different Thread Groups - you can take a look at following solutions:
__setProperty(), __threadNum() and __P() functions combination like:
To set the property:
${__setProperty(token_${__threadNum},${jmeter-variable-holding-the-token},)}
To read the property: ${__P(token_${__threadNum},)}
Use Inter-Thread Communication Plugin

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}.

JMeter - reusing random variables in another thread group

I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).
I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.
My current idea is to:
have one thread group that submits the posts
save a list of the randomly generated app_ids
in another thread group, read the list of app_ids and for each app_id, loop the status request
Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?
Also, if there is a better approach to this situation, I'm all ears :)
You can pass the values from one thread group to another one using __setProperty() function like:
${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}
Each time the function will be called it will generate a JMeter Property in form of
appid-1=foo
appid-2=bar
appid-3=baz
etc.
Where numbers like 1, 2, etc. are coming from __counter() function
In another Thread Group you will be able to access the generated values using __P() function like:
${__P(appid-${__counter(FALSE)},)}
Demo:
See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.
There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.
Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:
Thread Group
If [${__threadNum} == 1]
Samplers to check status
If [${__threadNum} != 1]
Samplers to submit posts
One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.
As for providing app_id to various threads/thread groups, you can use one of the approaches:
To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).
In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.
Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.
If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config

How to attach labels (from user defined variables) to jmeter response data?

I want to compare results of two sql queries of the following type
select count(*) from X where userid='${userid}'
where X is some subquery (different in both actual queries).
I want to check whether both of these queries return the same resultset using jmeter.
Hence, I created two jdbc requests in the thread group, and I supply the userids through a set of 50 userids stored in a csv file. All this works fine.
The core problem is that I have two samplers in a thread group, and I want to compare their results. I came across a similar question, which suggests to use a post-processor to store the response into a file.
However, being a newbie in JMeter, I could only manage to create 2 post-processors (1 for each request ) which write "prev.getResponseDataAsString()" to different files.
I get the following output, in one of the files
1
0
1
0
1
93583
1
42456
1
37033
1
37033
1
93583
It is clear from this result, that I have no idea which thread produced which result in the file, which brings me to my question.
How do I attach labels to jmeter response data?
There is a sampler called a "Debug Sampler"
And a counter config in your threads, so for each thread the count is incremented
If you add that debug sampler and change the title to "Debug printout Thread ${counterThread}"
Then that will show up in your view results tree
You can store result sets into a JMeter Variables and use i.e. Response Assertion or Beanshell Assertion to compare two variable values. Depending on response data type the approaches may differ.
Check out Debugging JDBC Sampler Results in JMeter article to learn how to work with JDBC test elements results, if anything remains unclear update your question with more details.

Resources