Jmeter Cross-Platform Path config issue - jmeter

I am working on master-slave Jmeter configuration, my data set exist on each machine on a different path for (macOS, Windows).
I use a global data set to fetch data for multiple thread groups.
However, the variable/property can be different across platforms.
I also tried the JSR223 to check the, but still no luck. check out the below snapshot.
I am trying to make sure that once I ran my test from Master (Mac), it also run on Windows.
Any thoughts how to do that on multiple platform setup.

The best solution is placing your test data under the same path which will be relative to JMeter working directory, this way you will not have to change anything in your script.
If for some reason you cannot afford this you can add a JSR223 Sampler to your Test Plan and use the code like:
if (org.apache.commons.lang3.StringUtils.containsIgnoreCase(System.getProperty('os.name'), 'Windows')) {
vars.put('data-path', 'c:/windows/specific/path')
} else {
vars.put('data-path', '/macos/specific/path')
}
It will detect the operating system name in the runtime and you will be able to define an OS-specific paths using the above approach.
vars is a shorthand for JMeterVariables class instance, the above code defines ${data-path} JMeter Variable which you can use later on for specifying data files locations. See Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about JMeter API shortcuts exposed to JSR223 Test Elements

Related

How to run environment based execution using same set of script in jmeter

I need to run same script in different environments like QC, UAT and PROD. I would like to know how do we configure and run based on specified environments.
Note - I tried with properties file but it requires some manual effort which we do not want.
Please help with some examples
If environments don't change you can create 3 separate HTTP Request Defaults configuration elements containing protocol/host/port/path/etc. settings for different environments and depending on the target environment you can toggle this or that HTTP Request Defaults element.
If you need unattended way of enabling/disabling HTTP Requests Defaults (or any other test element) you can consider using Taurus tool as a wrapper, it provides syntax to enable/disable any JMeter test element via YAML config or via command-line arguments.

Relative path to jmeter target folder in Jmeter GUI

I want to save Jmeter aggregate report to project's target folder with timestamp,so that everytime I run the tests I get the new unique report, irrespective of OS.
I tried by providing this path /target/jmeter/results/aggReport.csv but it saved it in C:/target/jmeter/results/aggReport.csv Also there was no time stamp.
E.g. 100320182130aggReport.csv which is mmddyyyyhhmmaggReport.csv
This question is in continuation of soemthing I wanted to achieve here and suggested by Dmitri Jmeter: Test plan has two thread groups but it generated only 1 jtl report
I am using Maven, Java 8, Windows 7
Update:
I tried:
In case of JMeter test execution via Maven JMeter's working directory (or Java user.dir property) points to target/jmeter/bin folder so you need to construct the desired path relative to it
Your path starts with / which means it is absolute and points to root folder of the file system
You need to include __time() function into the resulting filename if you want the result to be prepended by the timestamp
Assuming all above your listener "Filename" field should look like:
../results/${__time(MMddyyyyhhmm,)}aggReport.csv
Check out Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on various ways of kicking off a JMeter test including using Maven plugin.

Read system property from a target server for JMeter GUI tests

I'm running tests on JMeter on a target server. So I start JMeter(GUI) on my Mac but it points to a Linux server and runs tests against it. I need to read a system property on the target server and use that in my If Controller.
System.getProperty("prop_name"); works if the property is defined on my mac. But it doesn't pick it up from the target server.
Any suggestion is much appreciated!
Thanks!
I can suggest 2 options:
If your application under test has JMX enabled - you can read the "interesting" property value in one of JSR223 Test Elements using Groovy code. The properties can be queried from the RuntimeMXBean.
See Java Management Extensions (JMX) Technology Tutorial for more information.
If there is no JMX exposed to the outer world you can still try to get the property value remotely. Be aware that you can run any command or program on remote Linux instance using SSH Sampler. SSH Sampler can be installed using JMeter Plugins Manager.
See How to Run External Commands and Programs Locally and Remotely from JMeter for more information.

how to run tests as per respective suite in jmeter

I have created some testcases in Jmeter.
Now I want to run them separately example smoke testcases only.
Is there any way in Jmeter so I can run my JMeter project for a particular group/collection/suite only.
Is Jmeter provide any annotation or containers mechanism from where I can achieve same.
I have written my cases in Jmeter in below assertions
JSR223 Assertion
Response Code
Response Text
Any workaround will be helpful and appreciated in advance
The right way to module your JMeter scripts is to save small script in different JMXs and combined them by calling each or inside a bigger JMX file which uses Include Controller to execute different JMX files
The include controller is designed to use an external JMX file. To use it, create a Test Fragment underneath the Test Plan and add any desired samplers, controllers etc. below it. Then save the Test Plan. The file is now ready to be included as part of other Test Plans.
Inside JMX you can also use Module Controller to reduce code duplication
The Module Controller provides a mechanism for substituting test plan fragments into the current test plan at run-time.
If you want to execute specific test I suggest send specific properties and check the property inside an If Controller .
for example call with property jmeter -JexcludeTest1=true ...
And add an If Controller before test 1:
"${__P(excludeTest1)}" == "true"
The easiest way is using Taurus tool as a wrapper for your JMeter script, it has Modifications for Existing Scripts feature where you can define which test elements you want to enable/disable during test execution.
scenarios:
modification_example:
script: tests/jmx/dummy.jmx
modifications:
disable: # Names of the tree elements to disable
- Thread Group 1
enable: # Names of the tree elements to enable
- Thread Group 2
See Navigating your First Steps Using Taurus to get started.
Another option is putting requests you would like to enable/disable on demand under If Controllers so you could set "run/not run" condition dynamically.

How do I write a Jmeter script without using the GUI?

Is there a way to create a JMeter test plan without going through the GUI?
I.E. can you create a script with pure code?
In a way - yes. You can create the JMX file in a text editor, but it would require knowing what every component needs.
You're better off creating in GUI mode and modifying the JMX file manually as needed.
Yes it's possible to write a test plan just by writing JAVA code.
The key classes to look into are:
StandardJMeterEngine - the main class which configures the Test Plan and executes it
HashTree - a special collection which holds Test Plan elements
A minimum of JMeter Controllers necessary to run the test.
Reference: http://blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui
I can write and run JMeter without GUI. JMeter use JMX file, as you can here.
Not entirely sure why you would want to write a JMX in this way? ... But yes, entirely possible if you understand the structure of the document.
You could use any basic text editor to achieve this (notepad / notepad++ for example).
A JMX file is a saved JMeter project in XML format. ~ Ref
Depending on your needs you could the browser editor from the JMeter Plugins website.
jmeter-plugins.org/editor/
Or simply save a basic JMX as a template and spend loads of time learning the structure, syntax and namings etc.

Resources