Jmeter - Graph variable - jmeter

During my JMeter test I am extracting a float value from the response message an saving it to a variable using Regular Expression Extractor, and I am also saving that value in the generated test result csv file. Now I want to be able to generate a graph of this extracted float value, but haven't figured out a way to do so, or have found and examples to create my own graph plug in to graph this value.

In next version of JMeter 5.0, you’ll be able to do that bu adding in user.properties this:
sample_variables=VarName
jmeter.reportgenerator.graph.custom_mm_hit.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_mm_hit.title=Graph Title
jmeter.reportgenerator.graph.custom_mm_hit.property.set_Y_Axis=Response Time (ms)
jmeter.reportgenerator.graph.custom_mm_hit.property.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_mm_hit.property.set_granularity=${jmeter.reportgenerator.overall_granularity}
jmeter.reportgenerator.graph.custom_mm_hit.property.setSampleVariableName=VarName
jmeter.reportgenerator.graph.custom_mm_hit.property.setContentMessage=Message for graph point label
In above example:
VarName is the name of your variable
custom_mm_hit would be a unique id for your graph, you should change it but always prefix with "custom_"
To configure and generate graph see:
https://jmeter.apache.org/usermanual/generating-dashboard.html
You ‘ll get a new Graph of value over time in Custom Graphs section.
To download nightly build which is stable snd will be very close to 5.0, see:
https://jmeter.apache.org/nightly.html

You can use Sample Variables property to save your float value into .jtl results file
Add the next line to user.properties file:
sample_variables=foo
Replace foo with your actual JMeter Variable Reference Name from the Regular Expression Extractor
When you run your test next time you will see an extra column in the .jtl results file holding your float variable value. Another option is setting this property via -J command-line argument like
jmeter -Jsample_variables=foo -n -t test.jmx -l result.jtl
See Configuring JMeter and Apache JMeter Properties Customization Guide articles for more information on tuning your JMeter engine using properties.
Once you get the value stored you can plot the chart using LibreOffice Calc or Microsoft Excel or equivalent.
If you want to come up with a plugin to plot the custom variable you can start with How to write a plugin for JMeter guide and then look into source of i.e. Latencies Over Time plugin which lives in GitHub

Related

How to correlate different values in a RegEx with multiple matches with JMeter- Correlation Recorder?

I have a problem in JMeter that I can't figure out how to solve.
Situation:
I want to load test an ASP.NET-website.
bzm - Correlation Recorder used for recording and correlation
ScriptResource and WebResource have multiple occurrences
Now I used following RegEx to extract the ScriptResource values: <script src="(.+/ScriptResource.+?)". Then I stored the 3 matched values into 3 different variables. But I can't replace the values in the found order.
Example:
First Match: stored in : AspNet_ScriptResource
Second match stored in: AspNet_ScriptResource_1
Third match stored in: AspNet_ScriptResource_2
The three matches have all different values, can't paste one value into all 3 matches.
So I have to write the value from AspNet_ScriptResource into the first match (matchNr=1).
AspNet_ScriptResource_1 into second match (matchNr = 2) and
AspNet_ScriptResource_2 into third match (matchNr = 3).
But in the Correlation Rules (in the Correlation Recorder) in the "Correlation Replacement" section, there is no option to choose in which matchNr to write.
Correlation Recorder: Correlation Rules
I tried to use a BeanShell Preprocessor with a for-loop but I only found a way to write in the logs, not in the response body.
Is there a way to solve this with the Correlation Recorder plugin? If not, what options do I have to handle such a scenario?
Thanks for your help! :)
You can raise an enhancement request for the bzm - Correlation Recorder via JMeter Plugins support forum or if you're a BlazeMeter customer and need this piece of functionality asap - you can open a support ticket for implementation of the feature.
Currently it seems that the Correlation Recorder expects you to provide a regular expression either with the unique match or you will have multiple substitutions with the same value.
With regards to Beanshell approach:
You can substitute response data, but not with the PreProcessor, you need to do this via the PostProcessor using prev.setResponseData() function
Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
If you need to change request data, not the response data, you can do this via sampler.getArguments() function

How to display the variable value in the summary report

For each sampler result I have a variable value which I want to show it in the summary report as a test result. How to write this value in the jtl file and show it in the summary report?
You can write the variable into a file using sample_variables property.
Add the next line to user.properties file:
sample_variables=foo
replace foo with your actual variable name
Restart JMeter to pick the property up
That's it, an extra column will be added to the .jtl results file holding the foo variable value for each SampleResult
With regards to displaying it in the summary report, this is not something you can do out of the box, however you can plot the variable value as a chart in the HTML Reporting Dashboard. If this is something you're interested in - add the next lines to user.properties file:
jmeter.reportgenerator.graph.custom_testGraph.classname=org.apache.jmeter.report.processor.graph.impl.CustomGraphConsumer
jmeter.reportgenerator.graph.custom_testGraph.title=Foo values
jmeter.reportgenerator.graph.custom_testGraph.property.set_Y_Axis=Foo values
jmeter.reportgenerator.graph.custom_testGraph.set_X_Axis=Over Time
jmeter.reportgenerator.graph.custom_testGraph.property.set_granularity=60000
jmeter.reportgenerator.graph.custom_testGraph.property.set_Sample_Variable_Name=foo
jmeter.reportgenerator.graph.custom_testGraph.property.set_Content_Message=Foo value :
again, replace foo with your actual JMeter Variable name
References:
Sample Variables
JMeter Properties Reference
Apache JMeter Properties Customization Guide

Jmeter. __base64Encode function doesn't encode in JSR223 Sampler

Every time I need to achieve something in Jmeter, I ask a question in SO...
To make a story short: my goal is to read Base64 encoded values from csv file line by line and save them into separate variables. According to this page (in order to decode them), there are functions ${__base64Encode} and ${__base64Decode}. I installed Custom Jmeter Functions Plugin and restarted the Jmeter. Another referral to this answer, there is an advisory to use JSR223 PostProcessor / Sampler, verbatim:
it is recommended to use Groovy for any form of scripting to consider
migrating to JSR223 PostProcessor
so I decided to give it a try. Below is my script to read csv files:
def csvFileLocation = new File("C://JohnDoe//MyWork//sensitive_data.csv")
def lines = csvFileLocation.readLines()
lines.eachWithIndex {line, idx ->
vars.put("Id_value_" + idx, line)
}
${__base64Decode(${Id_value_0}, first_variable)}
${__base64Decode(${Id_value_1}, second_variable)}
${__base64Decode(${Id_value_2}, third_variable)}
Then I saw something interesting:
2018-01-01 12:30:60,767 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in
JSR223 script JSR223 Sampler, message: javax.script.ScriptException:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Script10.groovy: 8: unexpected token: ! # line 8,
column 1. !ßïj[žÿ
I simply decided to test it on https://www.base64encode.org/ with a string this is the test of base64 encoding
However, Jmeter _base64Encode function produces completely different result:
vars.put("jmeter_variable", "this is the test of base64 encoding");
${__base64Encode(${jmeter_variable}, my_variable)}
log.info(${my_variable});
OUTPUT:
JHtqbWV0ZXJfdmFyaWFibGV9
My question: what type of encoding algorithm Jmeter uses? Should I be able to save already encoded values into the csv file and retrieve them to the original value with the help of __base64Decode function? Thanks for the help...
You need to replace these lines:
${__base64Decode(${Id_value_0}, first_variable)}
${__base64Decode(${Id_value_1}, second_variable)}
${__base64Decode(${Id_value_2}, third_variable)}
With these ones:
vars.put('first_variable', vars.get('Id_value_0').decodeBase64() as String())
vars.put('second_variable', vars.get('Id_value_2').decodeBase64() as String())
vars.put('third_variable', vars.get('Id_value_2').decodeBase64() as String())
vars is a shorthand for JMeterVariables class instance, it provides read/write access to JMeter Variables in current test element's scope.
As per JSR223 Sampler documentation you should avoid inlining JMeter Functions and/or variables into Groovy scripts as they may resolve into something which can cause your script compilation failure (like in your case) or unexpected behaviour. Moreover it does not align with Groovy's compilation caching feature therefore performance of your Groovy script even if everything will be fine from syntax perspective will be a big question mark.
So the most "natural" way from Groovy perspective will be using String.decodeBase64() function like demonstrated above. See The Groovy Templates Cheat Sheet for JMeter article to learn what else could be done with Groovy and how.

Is it possible to include jmeter variables in values obtained from CSV?

I have a csv file which contains a column named "query". One of the entires I have for query is /user/${id}/list/${list}.
What I would like to do is let jMeter overwrite the ${list} and ${id} variables in the query when it is passed to a HTTP Sampler with variable values already in use from previous steps in my test plan.
For example:
In test plan, create ${id} = 5 and ${list} = 10.
In test plan, open csv file that contains query string.
In test plan, perform use a HTTP Sampler. Path in query should be the query value passed from csv file.
3a. Jmeter should take query passed to sampler and replace ${id} and ${list} with the values stored to those variables within test plan (5 and 10).
Right now when I try this, the HTTP response comes back showing the request was made to /user/${id}/list/${list}, not /user/5/list/10.
Does anyone know how to force the substitution through jMeter?
Is it even possible?
I was able to figure this one out after a bit of head scratching.
JMeter allows you to overload variables (place references to variables within a variable) by using the __eval function.
To get around the issue, I left the csv file as is, with references to variables set. When I wanted to reference the query from the csv file and overload the variable placeholders with actual values I used ${__eval(${query})} - where query = the
Try to use __eval function instead:
/user/${__eval(${id})}/list/${__eval(${list})}
__eval function seems to be just your case.

JMeter does not replace ${SUBPANEL_RELATE_MODULE_g1} with its value

It's a long story, but I will try make it simple:
I generated MeterMaid XML files with SugarMMM; I chose only the Accounts module:
I converted above files to JMeter format with MeterMaid (I consolidated the tests into one file and named it "filename.xml"):
ruby GenMeter.rb --inputfile=filename.xml --outputfile=filename.jmx
I did the necessary CSV setup. All the CSV file contains is the login details (usr,pwd) for testing concurrent user logins. This part works well indeed.
When I run the test, I can see that a whole bunch of ${} variables are converted into corresponding values. Sadly, ${SUBPANEL_RELATE_MODULE_g1} doesn't get resolved... here's what the GET url (from View Results Tree Listener component) looks like:
http://localhost/sugarcrm/index.php?module=${SUBPANEL_RELATE_MODULE_g1}&action=Popup&hide_clear_button=true&mode=MultiSelect&create=true&metadata=undefined
Note that it's not the only variable that isn't resolved. The following screenshot shows the other tests that fail, all also caused by other variables not replaced by their corresponding values:
Here's how this variable is set up (which is well before the time it's used):
Here's what Debug Sampler says:
JMeterVariables:
CAMPAIGN_ID=CAMPAIGN_ID_ERROR
CAMPAIGN_NAME=CAMPAIGN_NAME_ERROR
CONTACT_ID=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g=4
CONTACT_ID_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_ID_g1=onclick="send_back('Contacts','
CONTACT_ID_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g3=');">
CONTACT_ID_g4=Prof
CONTACT_NAME=Prof
CONTACT_NAME_g=4
CONTACT_NAME_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_NAME_g1=onclick="send_back('Contacts','
CONTACT_NAME_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_NAME_g3=');">
CONTACT_NAME_g4=Prof
FOUND_ID=1
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#3c1635
MEMBER_OF_ID=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g=4
MEMBER_OF_ID_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_ID_g1=onclick="send_back('Accounts','
MEMBER_OF_ID_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g3=');">
MEMBER_OF_ID_g4=searchSearchForm
MEMBER_OF_NAME=searchSearchForm
MEMBER_OF_NAME_g=4
MEMBER_OF_NAME_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_NAME_g1=onclick="send_back('Accounts','
MEMBER_OF_NAME_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_NAME_g3=');">
MEMBER_OF_NAME_g4=searchSearchForm
OPPORTUNITY_ID=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g=4
OPPORTUNITY_ID_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_ID_g1=onclick="send_back('Opportunities','
OPPORTUNITY_ID_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g3=');">
OPPORTUNITY_ID_g4=value
OPPORTUNITY_NAME=value
OPPORTUNITY_NAME_g=4
OPPORTUNITY_NAME_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_NAME_g1=onclick="send_back('Opportunities','
OPPORTUNITY_NAME_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_NAME_g3=');">
OPPORTUNITY_NAME_g4=value
RANDOM_CHAR=o
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=o
RANDOM_CHAR_g1=o
RANDOM_STRING=value
RANDOM_STRING_g=1
RANDOM_STRING_g0=value
RANDOM_STRING_g1=value
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g=2
RECORD_NUMBER_g0=javascript:lvg_nav('Accounts', '3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g1=javascript:lvg_nav('Accounts', '
RECORD_NUMBER_g2=3250317d-6c79-b20d-5e36-4e0cb4746e84
SEARCH_FIELD=SEARCH_FIELD_ERROR
START.HMS=190308
START.MS=1309453388621
START.YMD=20110630
SUBPANEL_RELATE_MODULE=Accounts
TEAM_ID=seed-Teams8
TEAM_ID_g=4
TEAM_ID_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_ID_g1=onclick="send_team_to_form('Teams','
TEAM_ID_g2=seed-Teams8
TEAM_ID_g3=');">
TEAM_ID_g4=Ball
TEAM_NAME=Ball
TEAM_NAME_g=4
TEAM_NAME_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_NAME_g1=onclick="send_team_to_form('Teams','
TEAM_NAME_g2=seed-Teams8
TEAM_NAME_g3=');">
TEAM_NAME_g4=Ball
TESTSTART.MS=1309455500088
pwd=user1
usr=user1
UPDATE:
Here's after changing Template to $1$$2$$3$$4$:
And here's the Debug output (the Sampler is put just after regex Controller):
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#18fde89
RANDOM_CHAR=t
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=t
RANDOM_CHAR_g1=t
RANDOM_STRING=Tanzania
RANDOM_STRING_g=1
RANDOM_STRING_g0=Tanzania
RANDOM_STRING_g1=Tanzania
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=DOCTYPE
RECORD_NUMBER_g=1
RECORD_NUMBER_g0=DOCTYPE
RECORD_NUMBER_g1=DOCTYPE
START.HMS=100932
START.MS=1312531772599
START.YMD=20110805
SUBPANEL_RELATE_MODULE=Accounts
TESTSTART.MS=1312542237235
pwd=user1
usr=user1
Verify in your CSV dataset config, all variables are declared correctly (no typos, no omissions, no spaces before variable names, etc.)
I would also suggest putting a debug sampler high in your tree, as it will show you every variable and its value and can save a lot of time.
Edit:
It looks like your regex is setup incorrectly for creating multiple groups. If you look in your Debug sampler, you have SUBPANEL_RELATE_MODULE=Accounts but not SUBPANEL_RELATE_MODULE_g1= . This implies you don't have GROUPS setup.
In looking at your regex, the line template: $0$ is saying "only give me one group", whereas it looks like you want 4. Thus, you should try template: $1$$2$$3$$4$ the first match should be _g1 the second _g2 and so on. Check out the manual for details.
make judicious use of the ${SUBPANEL_RELATE_MODULE_g1} variable throughout the script after it gets defined by the Regular Expression Extractor. Verify it exists. Use it in Controller titles, test headings, at the beginning of tests, and at the end of tests.
That will help narrow it down
This way you can follow it along in the script to make sure it exists just before the moment it is used, and find where it's breaking down. Basically print statement debugging.
I don't know about sugar CRM or metermaid but for jmeter I had a similar problem with variable that were not resolve.
Check if this variable is declared somewhere or maybe you need to write a reg ex to extract that value from the previous request.
The problem I got It was that I extracted the variable from a CSV files
the variable name was CONTRACTNO, CLIENTNO
my URL : /SomeURL/bla?eventId=contractSelected&contractNoSelected=${CONTRACTNO}&applicationID=BLa
And it wasn't working so I changed the variable name in the csv file to :
CONTRACTNO,CLIENTNO (look that I removed a space)
Jmeter tend to be very picky with space in name and variable definition.
You are expecting the following values
${SUBPANEL_RELATE_MODULE_g1}
but you have configured the Regular Expression Extractor reference name as
"SUBPANEL_RELATE_MODULE"
There two options you can get the values
You have to change the ${SUBPANEL_RELATE_MODULE_g1} into ${SUBPANEL_RELATE_MODULE}
You have to change the Regular Expression Extractor reference name as "SUBPANEL_RELATE_MODULE _g1" to "SUBPANEL_RELATE_MODULE"
After this your values will be replaced properly.
It looks like your regular expression isn't picking up a match, your default value is set to "Accounts" and in your debug output that's the value of the variable. You'll only get match groups if the regular expression matches.
The View Results Tree listener now has a RegExp tester, so you can go to the request that you're trying to extract the variable SUBPANEL_RELATE_MODULE from the result in the results tree and choose RegExp Tester from the dropdown where it says "Text".
You can then run your regular expression on the response data in the RegExp tester and probably find that it doesn't match and then hone your regular expression so that it matches and update it in your Regular Expression Extractor.

Resources