How capture unique id's from different match count for every user with or with out regex - jmeter

I want to capture the id's for different users.when we put the load test or run with multiple usersin jmeter
I am capturing the id's of the users. Whem i am runing the script with different users the id was generating for the users.By using regex for the first user the id was generating in 5th match count position . For the second user the id was generating in 11 th position . For third user the id was generating in 46 th position . So i am unable parameterize these values through regex. So please help me how to pass id's for the corresponding user when we run script for more than 20 users. Without passing the correct id the scripit was failing .

As per JMeter Variables documentation:
Variables are local to a thread
So theoretically 2nd JMeter thread (virtual user) should know nothing about the variables which are set for the 1st JMeter thread and vice versa.
If you're hitting an endpoint which shows IDs for all users which are in the system, they you should apply some filtering in your regular expression so it would return only one match or consider other Post-Processor, i.e.
CSS Selector Extractor for HTML
XPath Extractor and XPath2 Extractor for XHTML and HTML where CSS selectors are not sufficient/powerful enough
JSON Extractor and JSON JMESPath Extractor are for JSON
JSR223 PostProcessor if none of the above can help to extract the unique ID for the user

Related

Jmeter - My response has multiple values of same id. I want to extract and pass these values incrementally to the next request

My response to a save action is somewhat like this-
"diagnosisId":45686,"confidence":0.0, --other text--
"diagnosisId":45966,"confidence":0.0,--other text-- etc. Say there are 27 diagnosis Ids.
Now i want to send request for the 1st Diagnosis Id in loop till the last id (multiple records/rows to save depending upon the diagnosis Ids).
Request is something like this -
"diagnosisId":45686,"confidence":0," etc.
I have extracted the Diagnosis Id using Regular Expression extractor and matched the first value -
"diagnosisId":(.+?),
How do I pass the values incrementally now?
Given you provide "Match No:" as -1 in the Regular Expression Extractor:
You will get the following JMeter Variables as the result (viewable via Debug Sampler):
At this stage you can add ForEach Controller and configure it like:
Input variable prefix: diagnosisId
Output variable name: anything meaningful, i.e. id
That's it, you can reference each consecutive ID as ${id} in the request(s) which will be the children of the ForEach Controller:
Another example: Using Regular Expressions in JMeter

How to Extract value of dynamic element in jmeter

I have multiple dynamic elements on single page and element contain multiple data my HTML code is following
onclick="AddRemoveMemberDeal(event,'1494576','cd691c62-32b2-444d-ad6f-79a6104e4ee5','3997800330','Flaxseed Meal','Bobs Red Mill','$2.99','2.99','1/19/2017','85','Whole Ground','Shaw\'s','2','https://products.mygrocerydeals.com/nw/200/0/3/3/3997800330.jpg?deal=cd691c62-32b2-444d-ad6f-79a6104e4ee5&upc=3997800330&chain=194'); return false;"
my recorded script values is following
{"IdMember":"1494576","DealId":"c2b20119-44f2-4839-83c8-5382afd48e04","UPC":"7430500116","Name":"Regular Apple Cider Vinegar","Brand":"Bragg","Custom_Price":"$5.49","Price":"5.49","Sale_End":"1/5/2017","Score":"80","Description":"null","ChainName":"Stop & Shop","CategoryId":"2","ImageURL":"https://products.mygrocerydeals.com/generic/baking-goods.jpg?deal=c2b20119-44f2-4839-83c8-5382afd48e04&upc=7430500116&chain=204"}
how can I extract all values dynamically?
You need to use Regular Expression Extractor (Post processor) which applies the regex on the HTTP Response and retrieve the values using groups.
Keep the Regex Extractor under the HTTP Sampler against which response you want to apply regex and retrieve the data.
Reference Name field is the variable in which the value will be saved.
References:
http://jmeter.apache.org/usermanual/regular_expressions.html
https://guide.blazemeter.com/hc/en-us/articles/207421325-Using-RegEx-Regular-Expression-Extractor-with-JMeter
Caprture multiple values in Single Regex Extractor

JMeter: how to vary request inside Thread Group

I have to write load tests for web application using JMeter. The application has items available for booking, each item has a 'Book' button. If some user clicks this button for item, it becomes unavailable for other users. My question is:
Is it possible to make JMeter threads to book different items (to make different requests) and how to implement it?
You should be able to determine what parameter is being posted by different "Book" buttons and modify nested requests as needed. Test plan structure should be something like:
Open Booking Page - HTTP Request
Get all Booking IDs - Post Processor
Book - HTTP Request
Where "Post Processor" can be
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
In case of multiple matches Post Processor will return multiple variables like
BookindID_1=some value
BookindID_2=some other value
BookindID_3=some other value 2
....
BookindID_matchNr=10
There are at least 2 options on how to proceed with these values:
Iterate all the values using ForEach Controller
Stick to current virtual thread number via __threadNum function so thread #1 will take BookindID_1 variable, thread #2 - BookingID_2 variable value, etc.
It is also possible to take random value using __Random function but it may result in request failure if item is not available.
The correct way of 2 variables combination looks like:
${__V(VAR1${VAR2})}
So combining BookingID_N and __threadNum will look like
${__V(BookingID_${__threadNum})}
See How to use JMeter Functions post series for more on what can be done via functions.
yes, If every item has static(predefined) unique id,descriptor,identifier then that can be parameterized using a csv config file or random no. generator and selector
Random no generator and selector will work only for integers but csv config is better/standard practice. If you need more help please paste your test plan here with explaination of your need.

How to extract value passed in the URL and use it as parameter in Jmeter?

I am using Jmeter for my performance testing and I am stuck at the point where I need to extract the value from the URL and pass it to Jmeter.
Here is the example:
Application requires user to create an order and then submit it on the next page
I am at a point where I can create an order using Jmeter.
In order to create a script to submit an order I have copied the url from the web page as passed it as a GET method '/order/submit/23'. This '23' number changes everytime I create a new order
The issue I am having here is when I run my jmeter script it creates another order with another number which then mismatch with the '/order/submit/23' url I have passed.
Is there any way to extract this number from the HTML code and pass it to Jmeter?
I looked into the HTML code and this number is a part of URL so not sure how I can extract it. Any suggestions please
I am looking for something like /order/submit/${var}
Thanks
If I understood you correctly, you need to extract some value from response. You can do it with two samplers:
XPath Extractor
RegEx extractor
I think xpath extractor more appropriate in your case

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