How do you mix JMeter command line args with Gui args? - jmeter

I am trying to run a single recording in various different ways without copying the recorded pages.
I have created two Property File Readers that look for:
C:\performance\jmeter\users_${__P(ttype)}.properties
and
C:\performance\jmeter\${__P(env)}_${__P(region)}.properties
where the ${__P(xxx)} variables are passed on the command line as so:
-Jregion=UK -Jenv=dev -Jttype=isolated
These property files load the following variables (for example):
- usercount=25
- duration=1800
- host.name=server1
- host.port=8546
These are used in the HTTP Request Defaults:
${__P(host.name)}
${__P(host.port)}
and Thread Group:
${__P(duration)}
${__P(usercount)}
This works fine. However, if I want to run the same test in the Gui for a single thread (to check it works), these variables are not populated and the test fails.
I can create a User Defined Variable element but these have the format
${xxx}
so cannot be used interchangeably.
Is there any way to do what I'm trying to do here, please?

Option 1: you can pass the same parameters via '-J` arguments as JMeter in the GUI mode respects them as well
Option 2: you can specify your properties values in user.properties file (located in JMeter's "bin" folder) like
usercount=25
duration=1800
etc.
The properties values passed over the command-line will override those, which are specified in the user.properties
See Apache JMeter Properties Customization Guide for more information on using JMeter properties
By the way, you ain't gonna need this Property File Readers, there is a possibility to add extra properties files in JMeter via -q command line argument.
-q, --addprop
additional JMeter property file(s)

Discovered another way to resolve this issue.
The __P() function can take a second argument that acts as the default if the first value isn't resolved.
So
${__P(host.name)}
${__P(host.port)}
become
${__P(host.name,server1)}
${__P(host.port,1234)}
This works as well.

Related

JMeter Report Generation Without Default saveservice

Is there a way to generate a report from a .jtl file if I had set some saveservice values to false such as below:
jmeter.save.saveservice.response_message = false
jmeter.save.saveservice.assertion_results_failure_message=false
Its complaining that it cant find them. I tried adding the column manually into the .jtl and just filling it with a null value but that didnt seem to work.
It is possible given the Results File Configuration properties are the same.
So if you run your test on one machine and generating the results on another machine - make sure that the jmeter.save.saveservice. properties are exactly the same, this way you should be able to generate the dashboard normally.
So if you put the next lines to user.properties file:
jmeter.save.saveservice.response_message=false
jmeter.save.saveservice.assertion_results_failure_message=false
the dashboard generation will be successful.
Another option is providing the properties via -J command-line arguments like:
jmeter -Jjmeter.save.saveservice.response_message=false -Jjmeter.save.saveservice.assertion_results_failure_message=false -g -o /path/to/dashboard
See Apache JMeter Properties Customization Guide article for more information on JMeter properties and ways of setting/overriding them.
The order of "columns" is defined under CSVSaveService and as of JMeter 5.3 you cannot configure it, if you decide to save some metric it must be in particular column, i.e. timeStamp will always be the first, elapsed the second, etc.
I figured out you can manually just enter the headers in the jtl/csv file and leave the column empty. As long as you have the necessary columns separated by commas and the saveservice deafult properties are included.
The headers need to be in the right order though as per a normal jtl results file. The headers dont seem to be able to be just added to the end.

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

what container we can use for global and environment variables in Jmeter for API testing

I am trying to use Jmeter for API automation testing.
But Jmeter hasn't provided any separate containers for global and environment variables similarly like SOAP-UI and Postman.
I tried to use property file which also shared among all the JSR223 throughout the project but property having many others keys too and I haven't got any option by which I can delete key which been initiated once. Moreover, I can update the value too which seems most preferable to use
Below code I am using to set and get the values
props.put("shubhamKey", "shubhamValue")
props.get("shubhamKey")
I can also update it using same key
props.put("shubhamKey", "shubhamNewValue")
But as I said we can't delete key once initiated and it seems dangerous to delete from properties as it has many other keys too which may be required by Jmeter internally
After seeing too many things I have seen "User Defined Variables" where I can specify my key-value pairs. I am able to get the value using below code:
vars.get("shubhamLocalVariable")
But I am not able to set the value using below code:
vars.put("shubhamUserKeyagain","shubhamUservalue")
neither I got any option by which I further update it or delete it.
so Is there any feasible thing to store variables in Jmeter which can be easily created/deleted/updated using the code and can even call by other containers like HTTP Request.
Moreover I also want a container which preserve the values so the next iteration and next time (any time like other day) it will start with latest values
User Parameters
Jsr223
Any workaround will be helpful and appreciated in advance
As for me, I'm using a JSR223 Sampler at the begining of every Thread.
And for me it works:
vars.put("checksums_1","")
vars.put("checksums_2","")
vars.put("checksums_3","")
Firstly you can delete properties by using:
props.remove("shubhamKey");
And if you use specific prefix/suffix it shouldn't effect JMeter internally.
User Defined Variables isn't the best way to handle dynamic values, it's used for static variables
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
But you can set variable by string or variable or function, e.g:
For defining variables during a test run, see User Parameters which use similar assignments.

How to Print variable in aggregate report jmeter?

I want to pass variable to aggregate report to distinguish request .How to print/pass a variable in aggregate report jmeter?
Option 1: you can add variable to Sampler Name so you will be able to figure out the variable value and distinguish samplers basing on their labels in the Aggregate Report as
Option 2: you can use sample_variables JMeter property. JMeter will append variable values to sampler metrics in results .jtl file. It will not be displayed in the Aggregare Report, but it will be possible to analyze .jtl file with Excel or equivalent.
To use "sample_variables" feature add the following line to user.properties file (it is located under /bin folder of your JMeter installation)
sample_variables=VAR1,VAR2,VAR3
You can "tell" JMeter to store single or multiple variable values along with request metrics.
JMeter restart is required to pick up amended property from the "user.properties" file. Alternative way is providing property via -J command-line argument as
jmeter -Jsample_variables=foo -n -t /path/to/testplan.jmx
See Apache JMeter Properties Customization Guide for advanced information on using, setting and overriding JMeter properties.

Using parameters as user Defined Variables?

We run our tests in non gui mode and pass in various parameters like Server, port, threads etc. We'd also like to run our test in GUI mode, and be able to change these parameters in the GUI.
What I wanted to do, was use 2x User Defined variable objects, and have one with static data we can edit, and another with parameters. That way the actual test plan doesn't change, but we can set variables as parameters, and just disable the static data one. Or disable the parameterized one when we want to run with static data.
But this doesn't seem to work - no errors nothing.
I do something similar, but I used a UDF for this.
What I did was set up my variables and use default values.
VARNAME VALUE
otl_PROTOCOL ${__P(otl_protocol,https)}
otl_PORT ${__P(otl_port,443)}
otl_THREADS ${__P(otl_threads,1)}
otl_REPS ${__P(otl_reps,1)}
otl_RAMP ${__P(otl_ramp,0)}
I did one for server name as well. This way, I can use the defaults here or I can pass in parameters in either the command line args or in my user.properties. This works very well for me.
How are you passing in values from non-GUI mode? via CSV, using properties, User-Parameters, etc.?
If CSV, this is an easy fix. Simply create a User Defined Variables (UDV) object at the Test Plan Level and "hard code" all your parameters (Server, port, etc.). Keep your CSV config. If you run in GUI mode, disable the CSV and enable the UDV. When you save the file, keep the CSV enabled and the UDV disabled - that way when you run from non-GUI it'll read the CSV file.
If using properties, I would do the following: Create a UDV with all your parameters (Server, etc.). Before entering values, copy the component so you have TWO identical UDVs. In UDV 1, enter the property value from the command line. In UDV 2, enter the "hard coded" values. Throughout your script, replace any references to the properties with variable references. It would look something like this:
UD1: UD2:
Name Value Name Value
SERVER ${__P(Server)} SERVER devdomain.com
PORT ${__P(Port)} PORT 4111
Some HTTP Request
Domain: ${SERVER}
If using user-parameters, it would be the same concept as above.
Actually i am using a function named as regular expression for getting value.
here i have to use variable under variable because there is lots of value with same boundary, so i have selected one paragraph as ${ABC} and fetching value from this paragraph ${XYLEM}. both the variable created as regular expression.tried with ${__V(ABC${XYLEM})};
${__setProperty{Search_Investment_Banking,$Investment_Banking}};

Resources