Jmeter - Changing values per environment - jmeter

I have a situation in jmeter while running the endpoint url keeps changing.
for example:
URL1 [QA]: Facebook/v1/account2
URL1 [dev]: Facebook/account
Some times end point url is changing but my scripts are same. How do I handle the end point change for the above conditions?

You should use different property values for qa and dev
You can simply send different value in command line -J
jmeter -Jpath=Facebook/v1/account2 -t your.jmx
And then in Path field get path property value using __P function:
${__P(path)}
If you have multiple properties you can add different property files using -q, e.g.:
jmeter -q dev.properties -t your.jmx
And your dev.properties will be
path=Facebook/v1/account2

Related

JMeter parametrization $URL

I have problem with set parametrize $url variable in Jmeter.
I must set parametrize because I will run my project test in three other URL addresses, because application is deployed for 3 others such as production, development and I also would like testing in local.
I have the following CSV file:
protocol
$url
${dev} http://10.200.XXX.XX/{$url}
${trial} trial.mycompany.io{$url}
${product} product.mycompany.io{$url}
How can I set this in JMeter, set parametrization my URL variable?
Your question is not very clear, moreover my expectation is that you shouldn't have JMeter variables reference in form of ${variable} in the CSV file, only "plain" data should go there.
With regards to running test on different servers I would go for creating 3 separate CSV files, i.e.
dev.csv with the following contents:
protocol,host
http,10.200.XXX.XX/
trial.csv with the following contents
protocol,host
https,trial.mycompany.io
product.csv with the following contents
protocol,host
https,product.mycompany.io
Once done you can add a CSV Data Set Config and set it up like:
And finally add HTTP Request Defaults to your Test Plan to read the values from the relevant CSV file:
So when you run JMeter without any parameters it will pick up dev.csv file and will go to 10.200.XXX.XX host
If you run JMeter like:
jmeter -Jenvironment=trial
it will pick up trial.csv and will go to trial.mycompany.io host
If you run JMeter like:
jmeter -Jenvironment=product
it will pick up product.csv and will go to product.mycompany.io. host
More information:
__P() function
Overriding Properties Via The Command Line

Jmeter - store variable data for an hour

Is there a way to access Jmeter variable data even after tests are run?
This is what i am looking for:
Run a test, store the data in a variable (test finishes in 2 mins)
Idle for 15 mins
Run another test
i want the variable in step 3, Without running step1 again.
The most straightforward choice is saving the variable(s) you need into JMeter's .jtl results file using Sample Variables property. In order to "tell" JMeter to save certain variable value you need to add the next line to user.properties file:
sample_variables=your_variable_name
Alternatively you can pass this property value using -J command-line argument
jmeter -Jsample_variables=your_variable_name -n -t ....
Once done you should see an extra column in the .jtl results file holding your variable values. You should be able to access these values using i.e. CSV Data Set Config.
See Configuring JMeter user manual chapter for more details.
Variables are per test. You need to use a resource as file.
Use propert file to save and load variable as follows:
Start jmeter with property file as -q my.properties
On your test check if property exists if exists skip step 1
If not - do step 1 and then add the variable to property file line as propName=propValue
See example

How to write Jmeter Regex into a file after extraction

In my Jmeter test, I am able to use REGEX Extraction, After extraction I want to write the value of the REGEX variable into a file
I found a workaround as using beanshell as mentioned here https://stackoverflow.com/a/15159521/4556894
Is there any clean way of doing it, May be some inbuilt features, which I am not aware of
It is possible to write variable values into JMeter .jtl results file. There is a JMeter Property called sample_variables
Optional list of JMeter variable names whose values are to be saved in the result data files.
Use commas to separate the names.For example:
sample_variables=SESSION_ID,REFERENCE
So if you run JMeter in command-line non-GUI mode as follows:
jmeter -Jsample_variables=myVariable -n -t /path/to/your/testplan.jmx -l /path/to/testresults.jtl
You'll get the output like
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,bytes,grpThreads,allThreads,Latency,"myVariable"
1425978657207,368,HTTP Request,200,OK,Thread Group 1-1,text,true,1591,1,1,367,YOUR_VARIABLE_VALUE
In above example column names are given for reference, they are not included into csv results file by default. This behavior is controllable via jmeter.save.saveservice.print_field_names property, set it to "true" to get column names printed along with results data.
You can also set sample_variables property value in user.properties file which lives under /bin folder of your JMeter installation or uncomment it in jmeter.properties file (same location)
For more information on JMeter properties and ways of setting and/or overriding them refer to Apache JMeter Properties Customization Guide

Writing to a file named with variables in distributed JMeter testing

Okay I've been having an issue with writing results to folders in JMeter.
I have set 2 variables, one for the name of the test and one for the submit date. I want the reports to be written to the folder named with these two variables.
Here's the variables:
TestRun = "Name of test"
DateRun = $__{time(dd-MMM-yyyy HH.mm.ss)}
The path of the folder to be written to looks like this:
C:\Tests\TestEnvironment\Results\\${TestRun}${DateRun}\file.csv
When I run it on the master machine, it's fine. It saves to the correct file and folder path, and ends up looking something like this:
C:\Tests\TestEnvironment\Results\Test Run 1 - 08-May-2014 08.55.47\file.csv
However, when I run it on remote machines, it saves it literally as below:
C:\Tests\TestEnvironment\Results\${TestRun}${DateRun}\file.csv
So I end up with a folder named "${TestRun}${DateRun}"
Am I missing something blindingly obvious, or is this an actual JMeter issue?
Thanks!
As per JMeter help:
-G, --globalproperty <argument>=<value>
Define Global properties (sent to servers)
e.g. -Gport=123
or -Gglobal.properties
You need to use -G key so your variables could be distributed across remote clients.
so something like:
jmeter -r -n GTestRun=SomeName -GDateRun=SomeTime -t /path/to/your/plan
should help.
Alternatively you can create a .properties file and pass it to remote JMeter Engines via the same "-G" option.
I expect that if you want to use JMeter __time() function you'll need to wrap it with __eval, elsewise it will be treated as a string. Alternatively you can use operating system commands to retrieve current date and time.
See Apache JMeter Properties Customization Guide for more information on dealing with JMeter Properties.

Jmeter global properties and Simple Data Writers

I am setting a Jmeter global property on the command line with the -G option. I try to use this property to alter the file name of a Simple Data Writer. However, In the data writer the __P function returns only the default.
jmeter -t ... --nongui ... -GFileName=MyFile.xml ...
So, I know that I am setting the global property correctly. Both the jmeter log and the Jmeter server log show that the value is being captured from the command line. However it still refuses write a file name with anything other than the default.
I use the following command
filename_${__P(FileName,Default.fl)}
How do I pass in a value at the command line so that I can use it as the file name for a Simple Data Writer?
Notes: I am using remote servers, so I must use -G, and I already have a primary data file output, so I cannot use -l .
Why not to use -J or -D directives to set your property?
Everything will work as you want in case of
-JFileName=MyFile.xml
or
-DFileName=MyFile.xml
In both the cases you can than further refer to this property in Simple Data Writer as ${__P(FileName,)}.
Well, I've got the same negative result as your while trying to use global (-G) property but I cannot find in your situation described any prerequisites to use global (-G) properties instead of local (-J) or system (-D) ones.
Global properties are defined to be sent to remote servers... are you executing test in client-server mode (jmeter-server started)?
Than, as per 18.3.9 Simple Data Writer
When running in non-GUI mode, the -l flag can be used to create a data file.
I.e. running
jmeter -n -t ... -l MyFile.xml
will give you the same result in MyFile.xml.
As additional note.
You can try to use JMeterPlugins solutions:
Flexible File Writer - instead of native Simple Data Writer.

Resources