How to pass values for User Defined Variables?

2,858 views
Skip to first unread message

Luc De Graef

unread,
Mar 20, 2012, 8:59:35 AM3/20/12
to Maven JMeter Plugin Users
Hello,

I want to pass some arguments to the JMeter test class. These User
Defined Variables should be used in every JavaSampler, so I merely
added them on the configuration pane of the Test Plan:

<TestPlan guiclass="TestPlanGui" testclass="TestPlan"
testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</
boolProp>
<elementProp name="TestPlan.user_defined_variables"
elementType="Arguments" guiclass="ArgumentsPanel"
testclass="Arguments" testname="User Defined Variables"
enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="PORT" elementType="Argument">
<stringProp name="Argument.name">PORT</stringProp>
<stringProp name="Argument.value">7001</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>

If I adapt the value 7001 to 8000, a 'GUI-driven' JMeter test responds
as expected.

For embedding it in mvn with your plugin, I tried the following :
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
<configuration>
<reportDir>${project.build.directory}/jmeter-reports</reportDir>
<propertiesJMeter>
<PORT>8001</PORT>
</propertiesJMeter>
</configuration>
</execution>

How should I define such user defined variables

Mark Collin

unread,
Mar 20, 2012, 4:02:11 PM3/20/12
to maven-jmeter...@googlegroups.com
Any properties that you specify in the <propertiesJMeter> block will be
added to the jmeter.properties file created in
<projectBaseDir>/target/jmeter/bin

Sound like you want to specify some user properties so you should really add
the properties in the <propertiesUser> block (although it should work if
they are added in the <propertiesJMeter> block as well, but it's better to
keep your variable definition separate to your JMeter configuration):

<configuration>
<propertiesUser>
<threads>10</threads>
<testIterations>5</testIterations>
</propertiesUser>
</configuration>

Or in your case specifically:

<configuration>
<propertiesUser>
<PORT>8001</PORT>
</propertiesUser>
</configuration>

This will then be accessible in your test by using the JMeter property
function:

${__P(PORT)}

You can also specify a default value (just in case the property isn't set)

${__P(PORT, 7001)}

Hope that helps.

Hello,

--
You received this message because you are subscribed to the Google Groups
"Maven JMeter Plugin Users" group.
To post to this group, send an email to
maven-jmeter...@googlegroups.com.
To unsubscribe from this group, send email to
maven-jmeter-plugi...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/maven-jmeter-plugin-users?hl=en-GB.


Arne Franken

unread,
Mar 20, 2012, 6:03:29 PM3/20/12
to maven-jmeter...@googlegroups.com
Hi Luc,

you can take a look at the example project here:


there is a configurable JMeter testplan included.
The POM and the testplan is fully documented, it even includes two test executions.

Cheers,
Arne

ccance...@gmail.com

unread,
Nov 5, 2012, 6:20:21 AM11/5/12
to maven-jmeter...@googlegroups.com
Hi all,
(inline)

> Sound like you want to specify some user properties so you should really add
> the properties in the <propertiesUser> block (although it should work if
> they are added in the <propertiesJMeter> block as well, but it's better to
> keep your variable definition separate to your JMeter configuration):
>

> Or in your case specifically:
>
> <configuration>
> <propertiesUser>
> <PORT>8001</PORT>
> </propertiesUser>
> </configuration>
>
> This will then be accessible in your test by using the JMeter property
> function:
>
> ${__P(PORT)}

This is nice but I'd like to specify variables inline (to the maven command)...
Not working example:
mvn clean package integration-test -DargLine="-Djmeter.target.host=MyInlineHost.org"

Is it possible?

Mark Collin

unread,
Nov 6, 2012, 1:27:20 AM11/6/12
to maven-jmeter...@googlegroups.com
You could specify a property in your POM file and then set that property as
the value used by some JMeter properties e.g.

<project>
[...]
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<my.log.level>2.6</my.log.level>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<propertiesJmeter>

<log_level.jmeter>${my.log.level}</log_level.jmeter>
</propertiesJmeter>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>

So here you could pass the following into the command line:

mvn clean package integration-test -Dmy.log.level=DEBUG

For more info look at Sonatype's maven manual:

http://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-
properties.html#resource-filtering-sect-user-defined


-----Original Message-----
From: maven-jmeter...@googlegroups.com
[mailto:maven-jmeter...@googlegroups.com] On Behalf Of
ccance...@gmail.com
Sent: 05 November 2012 11:20
To: maven-jmeter...@googlegroups.com
Subject: Re: [jmeter-maven-plugin-users] How to pass values for User Defined
Variables?

--
You received this message because you are subscribed to the Google Groups
"Maven JMeter Plugin Users" group.
To view this discussion on the web, visit
https://groups.google.com/d/msg/maven-jmeter-plugin-users/-/wq_Y3EoIc9kJ.

ccance...@gmail.com

unread,
Nov 6, 2012, 7:39:27 AM11/6/12
to maven-jmeter...@googlegroups.com
Solved.
Thank you,
Carlo Cancellieri
Reply all
Reply to author
Forward
0 new messages