JMeter Regular Expression extractor one to one mapping - jmeter

I have an application where 100 devices are shown on home page. Each device has a separate device ID. Which I am extracting using JMeter Regular Expression extractor.
My scenario is if
User1 logs in then it should click on Device1.
User2 logs in then it should click on Device2.
User100 logs in then it should click on Device100.
In above case what should be the 'Match No' in JMeter Regular Expression extractor.
If am putting 0 its taking random device number for each user, where duplicate may happen.
If am putting 1 its taking Device1 for all users.
Please let me know how can I handel this one to one mapping in JMeter Regular Expression extractor.

In a CSV define all the variables like UserName,Pwd,DeviceIDs. This will work as a one to one mapping.
In "user properties" add sample_variables=UserName,Pwd,DeviceIDs and save and restart jmeter.
Once it is done, in test plan use 100 Vuser and 1 loop. Now, all 100 mapping will be assign to 100 vuser and will be executed once. Also, in csv data set config, mark Recycle on EOF as False and "Stop thread on EOF" as True.

Related

JMeter Thread Groups - Is it possible to make the same instance of one behave as a time based or an iteration based element dynamically at runtime?

I am creating a JMeter Test Harness that will be run from Jenkins using "Build with Parameters' to set runtime parameters that are passed into JMeter as Properties using -J attributes.
End users will be given the choice of running tests either based on the number of iterations or a period of time.
I can easily interrogate a passed in property value to determine if an 'iteration' or 'time' based test type and in order to try this I have added variables (which may or may not be have values depending) for ALL of the Thread Group 'Thread Properties' fields as can be seen below. Each variable will have a value of either 0 or 1+ depending upon the Jenkins parameters passed in at runtime.
enter image description here
As I do not want to create 2 Thread Groups (one for iteration based, and the other time based) then use logic controllers or similar to control what way to test, is there a dynamic way to switch the Thread Group 'Thread Properties" behaviour at run time using the singular Thread Group?
enter image description here
Any help in making 1 thing do 2 things in my little world of JMeter will be greatly appreciate!!
Not really, with "vanilla" JMeter you can:
Set number of iterations to -1 for "duration" based test
Set duration to a very long value (a couple of years) for the "iteration" based test
Other options are in:
JMeter .jmx scripts are basically XML files and XML is a subset of text so you can use a text editor like sed to substitute values directly in the .jmx file
Taurus automation framework has a nice feature of modifying an existing JMeter test before launching, it allows overriding absolutely any property of absolutely any element.

Less Data is getting inserted database after running Jmeter script

I recorded .jmx script by recording Blazemeter tool.
I followed below steps:
Login into application.
By default user landed on page which is Search Page where Patient list is displayed.
Now I select Patient and Navigate to Flowsheet page by clicking on HD Flowsheet menu button. Patient selection is mandatory.
Saved Flowsheet.
Logged Out.
Thread Group Detail:
Action to be taken after a Sample error: Continue
Number of Threads(users): 10
Ramp-up period (seconds): 100
Loop Count: 1
Same User on each Iteration : Yes
After executing script with above Thread group, In database only 6 Flowsheet is getting inserted instead of 10 flowsheet.
I checked View Result Tree, It is showing no error and also in Summary report it is showing 0% error.
What can be root cause? What strategy I should follow in such cases to debug script?
JMeter automatically treats HTTP response status codes below 400 as successful, it won't do any extra checks for the "flowshit" creation or insertion simply because it doesn't know anything about it.
My expectation is that your test silently fails somewhere, add View Results Tree listener and inspect response details for each step, most probably you will see that either you're submitting the same flowsheet over and over again or your script got stuck somewhere.
If you want to add an extra layer of verification, i.e. ensure that response contains specific value, you can add a Response Assertion to each request and specify pass/fail criteria there
In general when it comes to modern web applications the chance you will be able to successfully replay recorded script is close to zero because there are multiple dynamic parameters involved like ID of the patient or flowsheet, cookies, tokens, etc. and these dynamic values need to be correlated

How can we ask jmeter to process the next record which has unique number

I need to click and submit a sequential record in my application every time a concurrent user logged in. should not select a same record because the submit button wont available for the same record if the concurrent user tries to select. I do have 40 pages which jmeter should automatically select next record every time user logged in. Per page 10 records will be there, and 300 concurrent users will logged in.
Please advise what need to mention in bean-shell?
JMeter doesn't "click" any buttons, it acts on HTTP protocol level therefore you need to investigate what network request does "button click" cause and what are the differences between them.
Most probably it's a matter of simple correlation, so you need to do something like:
Add setUp Thread Group to your test plan
Add HTTP Request sampler to the setUp Thread Group and configure it to iterate 40 pages and extract the unique numbers (or other unique button identifiers) using the suitable JMeter Post-Processor and store them into JMeter Variables. You should end with something like:
VAR_1=unique_number_1
VAR_2=unique_number_2
...
VAR_400=unique_number_400
Add JSR223 Sampler to the setUp Thread Group and use the following Groovy code to convert the variables to JMeter Properties
SampleResult.setIgnore()
vars.entrySet().each { variable ->
if (variable.getKey().startsWith('VAR_')) {
props.put(variable.getKey(), variable.getValue())
}
}
That's it, in the main Thread Group you can use __P() and __threadNum() functions combination so each thread (virtual user) will get its own "button" to "click" like:
${__P(VAR_${__threadNum},)}

How do I record a script in JMeter which adds a record in a website?

Currently, I am recording a script in jmeter by which I am adding a record in a website , but a problem is that while recording a script I am able to add a record in a website, but once recording has been done and after that if I will run a script again then, a script is not adding a record in a website.
can you please help me with this?
In the absolute majority of cases you will not be able to replay the recorded script without performing correlation.
Modern web applications widely use dynamic parameters for session management or CSRF protection so once you record your test you get "hardcoded" values and they need to be dynamic.
Assuming all above my expectation is that your test doesn't add record due to failed login or something like that. Inspect requests and responses using View Results Tree listener - this will allow you to identify which exact step is failing.
The process of implementing the correlation looks as follows:
Identify the element which looks to be dynamic either manually inspecting request parameters and look for "suspicious" patterns or record your test one more time and compare the recorded scripts looking for the parameters which differ
Inspect previous response and extract the dynamic value using a suitable post-processor. For HTML response times the best option is CSS Selector Extractor. It will allow you to extract the dynamic parameter value and store in into a JMeter Variable
Replace hardcoded recorded value with the variable from the step 2
Repeat for all dynamic parameters
Don't forget to add HTTP Cookie Manager to your Test Plan.

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