JMeter-从命令行更改用户定义的变量 [英] JMeter - Changing user defined variables from command line
问题描述
我正在尝试使用命令行在jmeter测试计划中更新用户定义的变量
jmeter- n -t SimpleJmxExample.jmx -l log.jtl -Jtestproperty = 202
您可以看到我正在使用-J论据。但是,这似乎没有什么不同?是否有更好/更广泛接受的方式为测试计划传递不同的变量?
这是我的jmx文件
<?xml version = 1.0 encoding = UTF-8?>
< jmeterTestPlan version = 1.2 properties = 2.1>
< hashTree>
< TestPlan guiclass = TestPlanGui testclass = TestPlan testname =测试计划 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 =用户定义的变量 enabled = true>
< collectionProp name = Arguments.arguments />
< / elementProp>
< stringProp name = TestPlan.user_define_classpath>< / stringProp>
< / TestPlan>
< hashTree>
< ThreadGroup guiclass = ThreadGroupGui testclass = ThreadGroup testname =线程组 enabled = true>
< stringProp name = ThreadGroup.on_sample_error> continue< / stringProp>
< elementProp name = ThreadGroup.main_controller elementType = LoopController guiclass = LoopControlPanel testclass = LoopController testname = Loop Controller enabled = true>
< boolProp name = LoopController.continue_forever> false< / boolProp>
< stringProp name = LoopController.loops> 1< / stringProp>
< / elementProp>
< stringProp name = ThreadGroup.num_threads> 1< / stringProp>
< stringProp name = ThreadGroup.ramp_time> 1< / stringProp>
< longProp name = ThreadGroup.start_time> 1358160198000< / longProp>
< longProp name = ThreadGroup.end_time> 1358160198000< / longProp>
< boolProp name = ThreadGroup.scheduler> false< / boolProp>
< stringProp name = ThreadGroup.duration>< / stringProp>
< stringProp name = ThreadGroup.delay>< / stringProp>
< / ThreadGroup>
< hashTree>
< HTTPSampler guiclass = HttpTestSampleGui testclass = HTTPSampler testname =测试Http响应代码 enabled = true>
< elementProp name = HTTPsampler.Arguments elementType = Arguments guiclass = HTTPArgumentsPanel testclass = Arguments enabled = true>
< collectionProp name = Arguments.arguments />
< / elementProp>
< stringProp name = HTTPSampler.domain> httpstat.us< / stringProp>
< stringProp name = HTTPSampler.port>< / stringProp>
< stringProp name = HTTPSampler.connect_timeout>< / stringProp>
< stringProp name = HTTPSampler.response_timeout>< / stringProp>
< stringProp name = HTTPSampler.protocol> http< / stringProp>
< stringProp name = HTTPSampler.contentEncoding>< / stringProp>
< stringProp name = HTTPSampler.path> / $ {testproperty}< / stringProp>
< stringProp name = HTTPSampler.method> GET< / stringProp>
< boolProp name = HTTPSampler.follow_redirects> true< / boolProp>
< boolProp name = HTTPSampler.auto_redirects> false< / boolProp>
< boolProp name = HTTPSampler.use_keepalive> true< / boolProp>
< boolProp name = HTTPSampler.DO_MULTIPART_POST> false< / boolProp>
< boolProp name = HTTPSampler.monitor> false< / boolProp>
< stringProp name = HTTPSampler.embedded_url_re>< / stringProp>
< / HTTPSampler>
< hashTree>
< HeaderManager guiclass = HeaderPanel testclass = HeaderManager testname = HTTP Header Manager enabled = true>
< collectionProp name = HeaderManager.headers>
< elementProp name = Cache-Control elementType = Header>
< stringProp name = Header.name> Cache-Control< / stringProp>
< stringProp name = Header.value>最大年龄= 0< / stringProp>
< / elementProp>
< elementProp name = Accept-Language elementType = Header>
< stringProp name = Header.name> Accept-Language< / stringProp>
< stringProp name = Header.value> zh-CN,en; q = 0.8< / stringProp>
< / elementProp>
< elementProp name = Accept elementType = Header>
< stringProp name = Header.name> Accept< / stringProp>
< stringProp name = Header.value> text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8< / stringProp>
< / elementProp>
< elementProp name = User-Agent elementType = Header>
< stringProp name = Header.name> User-Agent< / stringProp>
< stringProp name = Header.value> Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.11(KHTML,Gecko一样)Chrome / 23.0.1271.97 Safari / 537.11< / stringProp>
< / elementProp>
< elementProp name = Accept-Encoding elementType = Header>
< stringProp name = Header.name> Accept-Encoding< / stringProp>
< stringProp name = Header.value> gzip,deflate,sdch< / stringProp>
< / elementProp>
< elementProp name = Accept-Charset elementType = Header>
< stringProp name = Header.name> Accept-Charset< / stringProp>
< stringProp name = Header.value> ISO-8859-1,utf-8; q = 0.7,*; q = 0.3< / stringProp>
< / elementProp>
< / collectionProp>
< / HeaderManager>
< hashTree />
< ResultCollector guiclass = ViewResultsFullVisualizer testclass = ResultCollector testname =查看结果树 enabled = true>
< boolProp name = ResultCollector.error_logging> false< / boolProp>
< objProp>
< name> saveConfig< / name>
< value class = SampleSaveConfiguration>
< time> true< / time>
< latency> true< / latency>
< timestamp> true< / timestamp>
< success> true< / success>
< label> true< / label>
< code> true< / code>
< message> true< / message>
< threadName> true< / threadName>
< dataType> true< / dataType>
< encoding> false< / encoding>
< assertions> true< / assertions>
< subresults> true< / subresults>
< responseData> false< / responseData>
< samplerData> false< / samplerData>
< xml> true< / xml>
< fieldNames> false< / fieldNames>
< responseHeaders> false< / responseHeaders>
< requestHeaders> false< / requestHeaders>
< responseDataOnError> false< / responseDataOnError>
< saveAssertionResultsFailureMessage> false< / saveAssertionResultsFailureMessage>
< assertionsResultsToSave> 0< / assertionsResultsToSave>
< bytes> true< / bytes>
< / value>
< / objProp>
< stringProp name =文件名>< / stringProp>
< / ResultCollector>
< hashTree />
< Arguments guiclass = ArgumentsPanel testclass = Arguments testname =用户定义的变量 enabled = true>
< collectionProp name = Arguments.arguments>
< elementProp name = testproperty elementType = Argument>
< stringProp name = Argument.name> testproperty< / stringProp>
< stringProp name = Argument.value> 200< / stringProp>
< stringProp name = Argument.metadata> =< / stringProp>
< / elementProp>
< / collectionProp>
< / Arguments>
< hashTree />
< / hashTree>
< / hashTree>
< / hashTree>
< / hashTree>
< / jmeterTestPlan>
嗯,用 -J
参数,您正在设置属性,并在用户定义的变量配置-变量。它将定义两个不同的实体,尽管它们具有相同的名称,但它们将具有不同的值。
根据您的情况,您可以执行以下操作。
-
按照上面在问题中的命令行设置jmeter属性值
...- Jtestproperty = 202
-
在UDV配置中,使用属性值来设置变量:
testproperty = $ {__ property(testproperty ,,)}
或
testproperty = $ {__ P(testproperty,)}
-
在脚本中进一步使用
$ {testproperty}
。
同样,您也可以使用变量进行相同的操作,只需将属性称为 {__ P(testproperty,)}
即可在命令行中设置值。
I'm trying to update a "user defined variable" in a jmeter test plan using the command line
jmeter -n -t SimpleJmxExample.jmx -l log.jtl -Jtestproperty=202
as you can see I'm using the -J argument. However it doesn't seem to make any difference? Is there a better/more accepted way of passing in different variables for a test plan?
Here is my jmx file
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.1">
<hashTree>
<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>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1358160198000</longProp>
<longProp name="ThreadGroup.end_time">1358160198000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="Test Http Response Code" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">httpstat.us</stringProp>
<stringProp name="HTTPSampler.port"></stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
<stringProp name="HTTPSampler.protocol">http</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/${testproperty}</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.monitor">false</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
</HTTPSampler>
<hashTree>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="Cache-Control" elementType="Header">
<stringProp name="Header.name">Cache-Control</stringProp>
<stringProp name="Header.value">max-age=0</stringProp>
</elementProp>
<elementProp name="Accept-Language" elementType="Header">
<stringProp name="Header.name">Accept-Language</stringProp>
<stringProp name="Header.value">en-US,en;q=0.8</stringProp>
</elementProp>
<elementProp name="Accept" elementType="Header">
<stringProp name="Header.name">Accept</stringProp>
<stringProp name="Header.value">text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</stringProp>
</elementProp>
<elementProp name="User-Agent" elementType="Header">
<stringProp name="Header.name">User-Agent</stringProp>
<stringProp name="Header.value">Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11</stringProp>
</elementProp>
<elementProp name="Accept-Encoding" elementType="Header">
<stringProp name="Header.name">Accept-Encoding</stringProp>
<stringProp name="Header.value">gzip,deflate,sdch</stringProp>
</elementProp>
<elementProp name="Accept-Charset" elementType="Header">
<stringProp name="Header.name">Accept-Charset</stringProp>
<stringProp name="Header.value">ISO-8859-1,utf-8;q=0.7,*;q=0.3</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>true</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="testproperty" elementType="Argument">
<stringProp name="Argument.name">testproperty</stringProp>
<stringProp name="Argument.value">200</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
Well, with -J
argument you are setting PROPERTY, and in User Defined Variables config - VARIABLE. It will define two different entities, although having the same name, they will have different values.
In your situation you can do the following.
Set jmeter property value in command-line as above in your question
...-Jtestproperty=202
In UDV config set variable with value from property:
testproperty = ${__property(testproperty,,)}
or
testproperty = ${__P(testproperty,)}
Use
${testproperty}
further in the script.
As well you can possibly do the same wihout using variable and simply refer property as {__P(testproperty,)}
to get value set in command-line.
这篇关于JMeter-从命令行更改用户定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!