2013-01-14 14 views
18

Sto cercando di aggiornare un "utente variabile definita" in un piano di test jmeter utilizzando la riga di comandoJMeter - Cambiare utente variabili definite da linea di comando

jmeter -n -t SimpleJmxExample.jmx -l log.jtl -Jtestproperty=202 

enter image description here

come potete vedere ho sto usando l'argomento -J. Tuttavia non sembra fare alcuna differenza? C'è un modo migliore/più accettato di passare in variabili diverse per un piano di test?

Ecco il mio file di JMX

<?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> 

risposta

32

Bene, con -J argomento che si sta configurando PROPRIETÀ, e in User Variabili definite config - VARIABILE. Definirà due entità diverse, pur avendo lo stesso nome, avranno valori diversi.

Nella tua situazione puoi fare quanto segue.

  1. Imposta il valore della proprietà jmeter nella riga di comando come sopra nella tua domanda (...-Jtestproperty=202).
  2. Nel variabile set di configurazione UDV con valore dalla proprietà:

    testproperty = ${__property(testproperty,,)}

    o

    testproperty = ${__P(testproperty,)}

  3. Usa ${testproperty} ulteriormente nello script.

Così si può eventualmente fare lo stesso utilizzando wihout variabile e semplicemente fare riferimento proprietà come {__P(testproperty,)} per ottenere valore impostato in-linea di comando.

+0

Perfetto .. grazie mille .. – CraftyFella

+2

$ {__ P (testproperty,)} non funziona ma $ {__ P (testproperty)} funziona. – drndivoje

+2

Potrebbe valere la pena aggiungere che è possibile impostare un valore predefinito dopo la virgola: '$ {__ P (testproperty, defaultvalue)}' – tokland

Problemi correlati