RogerParkinson
RogerParkinson

Reputation: 569

How to specify the groovy file in a JMeter JSR223 preprocessor under jmeter-maven-plugin?

I have several JMeter jmx files. They each have an initial script written in groovy and I specify that using a JSR223 PreProcessor giving the file name as src/test/jmeter/LoadScript.groovy. There are no imports, at least none I've written, only standard apache libraries.

This works just fine in the GUI environment. All my tests work and they share the same LoadScript.groovy file.

When I try and run this under maven using jmeter-maven-plugin it breaks because it comes up with a crazy looking path for the groovy file. eg

/home/roger/myproject/target/f4e97418-cbab-4ac8-ac4b-3bfbd686279a/jmeter/bin/src/test/jmeter/LoadScript.groovy

where I was hoping it would use just cwd plus the file path I specified.

I added this to the jmeter-maven-plugin to define a property with my basedir

            <configuration>
                <propertiesSystem>
                    <jmeter-base>${basedir}</jmeter-base>
                </propertiesSystem>
            </configuration>

and changed all my references to the groovy file to include ${jmeter-base}/ on the front. But still I get file not found references and now the path is:

/home/roger/myproject/datamanager-service/target/b9c995e2-699d-4d56-923b-a99afb566cfc/jmeter/bin/${jmeter-base}/src/test/jmeter/LoadScript.groovy

If this had worked it would have been a poor solution though because it would not allow the tests to be run under the GUI.

I would try having maven copy the files to the directory in the error message but the UUID in it is dynamically generated so that isn't possible as far as I can see.

There must be an easy way to do this. Anyone know what it is?

Upvotes: 1

Views: 914

Answers (1)

Dmitri T
Dmitri T

Reputation: 168147

JMeter Maven Plugin:

  1. Copies the contents of src/test/jmeter folder to target/jmeter/testFiles
  2. Sets the baseDir of the FileServer to that folder

So if you want to use relative paths - the paths need to be relative to this folder.

The easiest and the most flexible way would be using the following __groovy() function in the "File Name" field of your JSR223 Test Element:

${__groovy(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir(),)}/LoadScript.groovy

enter image description here

and it will be resolved in all cases:

  • running JMeter via maven as maven verify
  • running JMeter GUI via maven as mvn jmeter:configure jmeter:gui
  • running JMeter GUI from shell script or desktop shortcut and opening the .jmx script by browsing to it

More information: How to Use the JMeter Maven Plugin

Upvotes: 2

Related Questions