How to deal with dynamic parameter name in JMeter - jmeter

Login page is having dynamic password field name: every time user visits the login page field name looks like PASSWORD_673834937, and on next visit, it looks like PASSWORD_673857943.
I have created many scripts which were working as of today, but in latest build they bring in this change to the password field... before this it was always PASSWORD only. So all my scripts were failing. What is the workaround, so that all my scripts start working with dynamic field name?
OLD JMETER SCRIPT using name as "PASSWORD"
NEW changes to the password field

Under register.asp sampler, add RegEx Post-Processor
Specify the following parameters:
(i.e. the regular expression is <input TYPE="password" NAME="([^"]+)")
In HTTP Request, in the row where password is provided, specify variable created by RegEx Post-Processor in Field name, instead of static name. For example, since the variable I created above is called PasswordFieldName, the HTTP Sampler should look like this (omitting irrelevant parameters):

This is a matter of missing correlation, you would need this sooner or later given you continue playing with JMeter.
The idea of bypassing dynamic parameters is building your Test Plan as follows:
Request 1 (open login page)
Extract dynamic parameters and store them into JMeter Variables
Request 2 (perform login) providing credentials and all dynamic variables from the previous step
Add CSS/JQuery Extractor (be aware that it is not recommended to use regular expressions to work with HTML data) as a child of the register.asp page and configure it as follows:
Reference Name: anything meaningful, i.e. name
CSS/JQuery Expression: input[title=Password]
Attribute: name
Replace PASSWORD_673834937 with ${name} in the new script.

Related

In JMeter how do I set multiple dynamic variables in User Parameters or CSV Data Set Config

Very new to JMeter (and a long time Stack Overflow listener but first time caller so take it easy on me) so any help would be appreciated.
I am trying to set up a JMeter test that uses multiple dynamically generated access tokens to run across scenarios. I currently have a set of data using the CSV Data Set Config containing login credentials of a user's email and password for example:
email1#email.com,password1
email2#email.com,password2
Next I send a HTTP POST request to the Login service which generates an accessToken. Then, I am using the JSON Extractor to grab the generated accessToken. After that I am using the BeanShell Assertion to store the accessToken property/variable.
My issue seems to lie here in this last step since it will only store the last generated variable instead of each of the generated accessTokens. I want to be able to store/overwrite the grabbed accessToken for each email password combination. I would like it to modify/populate the CSV file like this:
email1#email.com,password1,accessToken1
email2#email.com,password2,accessToken2
I have also tried using the Pre Processor > User Parameters
Screen shot of User Parameters
I would like to have the "userBearerToken" variable update/overwrite along with the tests, but I cannot find a way to do so or if this can even currently be done.
I'm finding it difficult to word what I am trying to ask, but basically I want to store multiple dynamically generated variables (accessTokens that change and time out) and use them in other tests. I don't care which component can handle this (either the CSV or User Parameter), but I need to be able to store these variables with their corresponding email password credentials.
If you want to store the accessToken value into a JMeter property for using in other Thread Group(s) be aware that properties are global for the whole JVM and remain until JMeter is restarted so if you define a single accessToken property - each JMeter Thread (or iteration) will overwrite the value.
The solution is to use current thread (or iteration) number as prefix or postfix, this can be done using either __${__threadNum} function or relevant JMeter Variable depending on how iteration is defined or both.
Example setup:
In first thread group: ${__setProperty(access_token_${__threadNum},bar,)}
In second thread group: ${__P(access_token_${__threadNum},)}
Demo:
If you want to save the values into a file writing into the current one is not the best idea as you can (and most probably will) get malformed file due to a form of a race condition. So I would recommend using Sample Variables property instead.
If you add the next line to user.properties file:
sample_variables=email,password,accessToken
JMeter will store the variables named ${email}, ${password}, and ${accessToken} along with their values in the .jtl results file which is basically CSV file which can be re-used anywhere else.
However if you have a requirement to store only the credentials and the token you can go for the Flexible File Writer plugin and configure it to save the aforementioned variables values into a separate file, the relevant configuration would be as simple as:
variable#0,variable#1,variable#2
You can install Flexible File Writer plugin using JMeter Plugins Manager

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 performance testing :

I have a requested in jmeter that request created new one request, so I need that new one request url in a variable because new one request having a user I'd.
You can handle this situation in at least 2 ways:
Extract the dynamic part using Regular Expression Extractor:
Add Regular Expression Extractor as a child of the 1st request
Configure it as follows:
Field to check: URL
Reference Name: anything meaningful, i.e. id
Regular Expression:userId=(.*)
Template: $1$
Assuming everything goes well you should be able to refer extracted value as ${id} where required (manually add it to the end of each and every request)
You can semi-automate the process using Using the HTTP URL Re-writing Modifier, just add it as a child of the first request and put userId into "Session Argument Name" input field, JMeter should be smart enough to automatically add these "userId" postfixes to subsequent requests.

jmeter how to replay recorded unique id from application

I am very new to Jmeter and trying to use it for doing load testing my application.
In my application, every time we click on a template, application will allocate a unique id which to the template...when I recorded the steps using jmeter, a particular unique id was recorded...but when I tried to play the recorded case...it is looking for the same unique id....how do I tell jmeter to get the new id from the application?
Here are the steps
Login as a user,
click on a particular link,
click on a button which will then popup a window asking to select a template,
After selecting a template, my application will create a unique id for that template
It very much depends on whether that template ID is created on the client (i.e. by JavaScript), or on the server (i.e. you can actually record a template ID returned by the server).
If second is your case, then server returns template ID in the response to template selection, so you can use one of the post-processors - a supporting element invoked after the parent request; it usually extracts data from the response and saves it as a variable(s). In your case you'd extract template ID and save it as variable. Later samplers can use the variable in format ${your_name} instead of the recorded hard-coded string. So in that case your plan could look like this:
Which post-processor to use and how to use it depends on the response you are receiving form the server, so cannot be more specific here.
If the first option is your case (JavaScript on the client generates template ID; and your recording only contains usage of said ID), then you can simulate what JavaScript is doing by generating a similar ID using one of the JMeter script-related features: it could be random function, an inline piece of JavaScript code, a scriptable sampler, such as JSR223 Sampler, or... There are many options really, depending on concrete needs of that generated template ID. Again, a more specific question would help to narrow down your choices.
Classic "correlation" example.
Look for that generated ID in the previous responses (you can do it with the View Results Tree listener)
Once you detect it you need to extract it and convert into a JMeter Variable with a PostProcessor (the most commonly used is Regular Expression Extractor, however depending on the nature of your request you may consider to use others
Once you get the ID extracted and stored in the variable - substitute hard-coded value obtained via recording with the JMeter Variable
Repeat steps 1-3 for any other dynamic parameters or values. Or, consider a faster way of creating a JMeter test via alternative recording solution which performs the above steps automatically so you won't have to worry about detecting and handling dynamic elements. See How to Cut Your JMeter Scripting Time by 80% article for details.
You need to check response of the previous request. Normally ID will be created and can be found in the response of previous request and you can use that ID for next request.
You need to first find in which response the ID is being generated and the format of the ID. You can use firebug to see the response in HTML format and find where the id is.
Once you have the format of the id, create regular expression around it. Test it using regex tester that comes with JMeter. Or you can use rubular.com to check the correctness of your regex.
Once you have correct regex, use regular expression postprocessor on the request which returns the id and then use that variable in actual request that uses unique id.

How to handle dynamically generated values during run time via Jmeter

Scenario: I am recording a script which is fetching values from CSV name and email. I have used ${email} and ${name} at the time which candidate is registering. Every time candidate register, unique instance Id is generated on the basis of which further action is performed.
Ex:
Candidate registers -> Unique Id (say 12345) -> ST : Start some test
on the website -> Some responses saved for 12345 -> FT : Finish test
on website
Need to perform the same for say 500 candidates. I am fetching unique email and name from csv.
How do i store/handle unique instance Id for each candidate dynamically and perform the entire operation?
Currently each operation is getting performed for same unique instance Id (12345) with 0% error.
Let me know if any other details needed for the same.
UPDATE from comments:
I can use say UniqueId whenever candidate registers using a RegEx Extractor or a XPath Extractor and i can pass that value in further process.
Now issue is i have to pass the stored variable in JSON.
No clue about that.
Since you've extracted UniqueId value using any extractor component it's stored in jmeter variable (pointed in the extractor's configuration) and can be referred as e.g. ${uniqueId}.
To pass into the further request you can use HTTP Request where in Post Body you can set your JSON request code with ${uniqueId} inserted in the right place.
You can use regular expression extractor in jmeter to extract required variable value and store reference it with a variable name .
Later it can be used in later requests by usin ${variablename}
In the regular expression extractor you can use perl5 regular expressions
Refer to this link for additional information:
http://www.jmeter4u.com/2013/04/chapter-6-handling-dynamic-server-values.html

Resources