How to differenciate store token in .csv jmeter - jmeter

Need help.
Need to log in multiple users, so, I'm using CSV Data Set Config. Received dynamic authCode I'm storing in another .csv file, and as the result finaly I'm receiving token, which I also store in .csv.
While posting HTTP request I'm passing token with user data from .csv, How can I differentiate tokens, to post 1000 of request using 4 users only?

Short Answer: JMeter automatically does it for you. you no need to save authCode & token in the CSV files.
Long Answer:
Save the authCode using Regular Expression Extractor. name the variable as authCode.
Replace with ${authCode} wherever authCode value is sent in subsequent requests.
Capture the token value using Regular Expression Extractor and store the value in a variable token
Replace with ${token} wherever token value is sent in subsequent requests.
you no need to worry about the thread/vuser, to associate authCode, token and the corresponding thread. JMeter handles it for you by storing those authCode, token values for each thread and maintains the state.
For more specific answer, please share your Test Plan and mention what exactly you want to achieve.

Related

Jmeter token refreshing

I find the topic Refreshing Auth Token while keep the requests running in JMeter 3.3. I faced with same task - token refreshing each x time and other request sending at the same time. I've seen that author has find the solution. But I would be really appreciated if you could share the logic. I tried with global property in Jmeter, but it seems that I set one token for all users. The timer was allso added, but I'm getting one token for sessions. Probably we have a new solution for Jmeter 5.x. Thanks.
The solution would be the same, you just need to amend it a little bit and use __threadNum() function in order to create thread (virtual user)-specific properties.
Something like:
${__setProperty(token_${__threadNum},variable containing the token,)}
will generate the following JMeter properties:
token_0=token for the first virtual user
token_1=token for the second virtual user
etc.
which can be accessed similarly using __P() function like:
${__P(token_${__threadNum},)}
More information: Here’s What to Do to Combine Multiple JMeter Variables
Thank you so much! I have implemented my script using the following logic in one thread group:
Set var “Trigger” = 60 seconds (token refreshing interval, per minute);
Login user;
Get Token request; and execute actions:
Extract Token and save to vars;
Save “TokenTime” to vars (where “Login” from CSV is the name of property);
Calculate “TokenDiffTime” = “TimeNow- TokenTime” -> Save as property with unique name (the unique name can be the string “Login”+”TimeDiff”- where “Login” is dynamic Login from CSV and “TimeDiff” – just static string; the example of property name is “User1TimeDiff”).
Loop controller with logic:
If Controller (Is token Actual? -> check “TokenDiffTime” >=“Trigger”) -> Call Refresh Token request; Extract actual token.
Invoke App request; using actual token.
If Controller (Is token Actual? -> check “TokenDiffTime” >=“Trigger”) -> Call Refresh Token request; Extract actual token.
Invoke App request; using actual token.
So, such logic takes into account the response time delays and a new app request is invoking with actual token. “Trigger” is flexible value to set token refreshing interval. Hope such topic could be useful to someone.

JMeter RegUx User Parameters not adding parameter

New to JMeter, and I'm probably missing some simple thing but I can't find it anywhere.
I'm trying to log into a web application so I send a GET request to the home page to retrieve the csrf token and then I use the regular expression extractor to retrieve it:
I then try to place the extracted token into the POST request:
But the extracted token doesn't show up in the request sent via the View Results Tree. Only the UserId and Password are passed which I manually defined:
My regular expression is finding a match as you can see here:
but even if it wasn't finding a match, it should still pass "NotFound" correct?
Any help is greatly appreciated!
Edit: Added a Debug Sampler and it is correctly showing the variable Token with it's correct value. So Token just isn't being added to the request via the RegEx User Parameter Pre Processor.
It's difficult to see what you're doing without seeing the LoginPage step, but you need to make sure you are adding the csrf token you've extracted in the right place.
Typically it could be as a query param, part of a post body or an http header.
As you can see the token has been extracted from your initial response in the Debug sampler, there must be something wrong in how or where the token is being applied to the LoginPage request. (As you say the RegEx User Parameter Pre Processor isn't adding it)
I've never used the PreProcessor and the Jmeter documentation explanation is a bit vague on what it does, but you can add the variables into your request without it using the variable saved for the capture groups - for input name this will be ${Token_g1} and for value it will be ${Token_g2} - which you will be able to see from the Debug Sampler. You'll need to add a Header or Cookie Manager to the Login Page element if this is where the token is.
By setting the template in the Extractor to $1$$2$ you create a variable with the name and value concatenated together. I'm not sure why you would need this, and I would guess that the name doesn't change - in which case you can just use capture group 2, or if you want to use the Variable name Token then update your template to be $2$

Jmeter is converting '#' in the Password into junk character

I am recording Login in Jmeter. Password has '#'. Jmeter recorded exact string but when i run the same, '#' is converted to '%40ss' and login is getting failed(login is failing even if i pass parameters through csv file). But if we pass parameters through jmeter Body Data, Login is successful. I dont want to pass through Body Data, i want to send parameters through CSV file. How to achieve this. Please find the attachments
Recorded and Response
My expectation is that it is only a matter of representation, i.e. when I run similar request using a sniffer tool like Wireshark I can see # sign as a part of form data.
Most probably your problem lies somewhere else, i.e. you haven't correlated this __RequestVerificationToken or haven't added HTTP Cookie Manager.
When it comes to load testing ASP.NET web applications you cannot just record and replay your test, you need to perform correlation of dynamic parameters, check out ASP.NET Login Testing with JMeter article for more details.
Lakshmikanth, when you are passing any special character in parameters values then JMeter converts that character into percent-encoding for eg. '#' converts to '%40', '!' converts to '%21'.
To overcome this issue you can pass your password as it is [say P#ssword] in the .csv file but in your request you need to uncheck the encode checkbox corresponding to your password parameter.

I want to generate regular expression for the session token ct=KWG3-Q49R-1FAX-YO56 in JMeter

I want to generate regular expression for the session token ct=KWG3-Q49R-1FAX-YO56(It changes dynamically) in JMeter
First of all, you need to locate the Session Token parameter which is being posted to the Server. It may resides on Request URL, Request Body, or Request Header.
Then, you need to find out the Session Token which gets retrieved from the Server. It may be on any of the previous requests and may retrieved through Response Body, or Response Header.
Now, add the Regular Expression Extractor Post Processor in the request in which Session Token is found. If the original Session Token Expression is as;
ct=KWG3-Q49R-1FAX-YO56
Then try this Regex:
ct=(.*)
Note: Also add a Debug Sampler in your Testplan/ThreadGroup in order to verify your Regex.

Feature Testing using jmeter

Can somebody please explain me how can I use JMeter for Feature testing?
I'm able to create multiple HTTP requests within a Testplan. But I need know the way to capture the previous API response and pass one of the response data to the next API request.
Eg:
1.Create Account.
Request- POST: /account
Response: ID: "Value"
Read account
Request- GET: /account/
JMeter is really more of a load testing tool, and best used as such. Capturing data from responses is possible using the Regular Expression Extractor, which can store extracted values in variables for use in a subsequent request. It is a bit of a pain in the ass to use, though.
On your request, add a Regular Expression Extractor:
Field to check: body
Reference name: EXAMPLE
Regular Expression: \[.*\] #your regex here, stuff in square brackets as example
Match No.: 1
In a subsequent request, you can then use the variables defined by the extractor, e.g. ${EXAMPLE_g0} for the entire match, or ${EXAMPLE_g1} for group 1, etc.

Resources