admin管理员组

文章数量:1410737

I am running a load test using JMeter and I want take the ConstantThroughputTimer value as user input and set in the JMX XML. The JMeter shell script is being called from a bash script.

Bash Script:

THROUGHPUT_VALUE=121
THROUGHPUT_VALUE=$(echo "$THROUGHPUT_VALUE" | awk '{printf "%.1f", $1}')

$JMETER_INSTALL_DIR/jmeter.sh -n -t $JMETER_LOAD_PROFILE_CONFIG/$PROFILE_FILE_NAME -JThroughput=$THROUGHPUT_VALUE


    

JMeter JMX XML (This is not complete XML. Just a snippet of the full XML where user defined variable and Throughput time is declared)

   <UserParameters guiclass="UserParametersGui" testclass="UserParameters" testname="User Parameters" enabled="true">
    <collectionProp name="UserParameters.names">
      <stringProp name="904465283">CurrentDay</stringProp>
      <stringProp name="-2026347353">CurrentDate</stringProp>
      <stringProp name="-2025863226">CurrentTime</stringProp>
      <stringProp name="690807817">FinalDate_Header1</stringProp>       
      <stringProp name="-323914198">throughput</stringProp>
   </collectionProp>
   <collectionProp name="UserParameters.thread_values">
      <collectionProp name="-548354585">
        <stringProp name="603506847">${__time(E,)}</stringProp>
        <stringProp name="-1521574952">${__time(YYYY-MM-dd)}</stringProp>
        <stringProp name="1821498968">${__time(HH:mm:ss)}</stringProp>
        <stringProp name="52928079">${__time(E\, dd MMM yyyy\, h:mm:ss,)} +0000</stringProp>
        <stringProp name="1446819321">${__P(Throughput)}</stringProp>
      </collectionProp></collectionProp> </UserParameters>


   <ConstantThroughputTimer guiclass="TestBeanGUI" testclass="ConstantThroughputTimer" testname="Constant Throughput Timer" enabled="true">
      <intProp name="calcMode">0</intProp>
      <doubleProp>
        <name>throughput</name>
        <value>${__P(Throughput)}</value>
        <savedValue>0.0</savedValue>
      </doubleProp>
    </ConstantThroughputTimer>

But JMeter is throwing error

Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/mnt/Test.jmx'. 
Cause:
NumberFormatException: For input string: "${__P(Throughput)}"
 Detail:com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : 
first-jmeter-class  : .apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:109)
class               : .apache.jmeter.save.ScriptWrapper
required-type       : .apache.jmeter.save.ScriptWrapper
converter-type      : .apache.jmeter.save.ScriptWrapperConverter
path                : /jmeterTestPlan/hashTree/hashTree/hashTree[3]/ConstantThroughputTimer/doubleProp/value
line number         : 461
version             : 5.5
-------------------------------
Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/mnt/Test.jmx'. 
Cause:
NumberFormatException: For input string: "${__P(Throughput)}"
 Detail:com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : 
first-jmeter-class  : .apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:109)
class               : .apache.jmeter.save.ScriptWrapper
required-type       : .apache.jmeter.save.ScriptWrapper
converter-type      : .apache.jmeter.save.ScriptWrapperConverter
path                : /jmeterTestPlan/hashTree/hashTree/hashTree[3]/ConstantThroughputTimer/doubleProp/value
line number         : 282
version             : 5.5

I even changed the property of the XML from

<stringProp name="-323914198">${__P(Throughput)}</stringProp> to <doubleProp name="-323914198">${__P(Throughput)}</doubleProp>

thinking that it's a float or double value. But still getting same error. Is there any way I can resolve this?

I am running a load test using JMeter and I want take the ConstantThroughputTimer value as user input and set in the JMX XML. The JMeter shell script is being called from a bash script.

Bash Script:

THROUGHPUT_VALUE=121
THROUGHPUT_VALUE=$(echo "$THROUGHPUT_VALUE" | awk '{printf "%.1f", $1}')

$JMETER_INSTALL_DIR/jmeter.sh -n -t $JMETER_LOAD_PROFILE_CONFIG/$PROFILE_FILE_NAME -JThroughput=$THROUGHPUT_VALUE


    

JMeter JMX XML (This is not complete XML. Just a snippet of the full XML where user defined variable and Throughput time is declared)

   <UserParameters guiclass="UserParametersGui" testclass="UserParameters" testname="User Parameters" enabled="true">
    <collectionProp name="UserParameters.names">
      <stringProp name="904465283">CurrentDay</stringProp>
      <stringProp name="-2026347353">CurrentDate</stringProp>
      <stringProp name="-2025863226">CurrentTime</stringProp>
      <stringProp name="690807817">FinalDate_Header1</stringProp>       
      <stringProp name="-323914198">throughput</stringProp>
   </collectionProp>
   <collectionProp name="UserParameters.thread_values">
      <collectionProp name="-548354585">
        <stringProp name="603506847">${__time(E,)}</stringProp>
        <stringProp name="-1521574952">${__time(YYYY-MM-dd)}</stringProp>
        <stringProp name="1821498968">${__time(HH:mm:ss)}</stringProp>
        <stringProp name="52928079">${__time(E\, dd MMM yyyy\, h:mm:ss,)} +0000</stringProp>
        <stringProp name="1446819321">${__P(Throughput)}</stringProp>
      </collectionProp></collectionProp> </UserParameters>


   <ConstantThroughputTimer guiclass="TestBeanGUI" testclass="ConstantThroughputTimer" testname="Constant Throughput Timer" enabled="true">
      <intProp name="calcMode">0</intProp>
      <doubleProp>
        <name>throughput</name>
        <value>${__P(Throughput)}</value>
        <savedValue>0.0</savedValue>
      </doubleProp>
    </ConstantThroughputTimer>

But JMeter is throwing error

Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/mnt/Test.jmx'. 
Cause:
NumberFormatException: For input string: "${__P(Throughput)}"
 Detail:com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : 
first-jmeter-class  : .apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:109)
class               : .apache.jmeter.save.ScriptWrapper
required-type       : .apache.jmeter.save.ScriptWrapper
converter-type      : .apache.jmeter.save.ScriptWrapperConverter
path                : /jmeterTestPlan/hashTree/hashTree/hashTree[3]/ConstantThroughputTimer/doubleProp/value
line number         : 461
version             : 5.5
-------------------------------
Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/mnt/Test.jmx'. 
Cause:
NumberFormatException: For input string: "${__P(Throughput)}"
 Detail:com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : 
first-jmeter-class  : .apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:109)
class               : .apache.jmeter.save.ScriptWrapper
required-type       : .apache.jmeter.save.ScriptWrapper
converter-type      : .apache.jmeter.save.ScriptWrapperConverter
path                : /jmeterTestPlan/hashTree/hashTree/hashTree[3]/ConstantThroughputTimer/doubleProp/value
line number         : 282
version             : 5.5

I even changed the property of the XML from

<stringProp name="-323914198">${__P(Throughput)}</stringProp> to <doubleProp name="-323914198">${__P(Throughput)}</doubleProp>

thinking that it's a float or double value. But still getting same error. Is there any way I can resolve this?

Share edited Mar 7 at 6:43 Suvendu Mandal asked Mar 6 at 22:00 Suvendu MandalSuvendu Mandal 1091 gold badge3 silver badges12 bronze badges 3
  • Please don't tag your titles. See How to Ask. – isherwood Commented Mar 6 at 22:02
  • Btw.: Your shown XML file is no valid XML file. – Cyrus Commented Mar 6 at 22:38
  • I haven't shared the complete XML. It's just snippet of the user parameters and constant throughput timer. Why do you think it's not valid? If I remove <value>${__P(Throughput)}</value> and put a double number then it's working fine. So XML is valid. – Suvendu Mandal Commented Mar 7 at 5:03
Add a comment  | 

1 Answer 1

Reset to default 1

It's better to use JMeter GUI for creating and editing test plans:

This results in the following XML configuration:

<ConstantThroughputTimer guiclass="TestBeanGUI" testclass="ConstantThroughputTimer" testname="Constant Throughput Timer">
  <intProp name="calcMode">0</intProp>
  <stringProp name="throughput">${__P(Throughput,)}</stringProp>
</ConstantThroughputTimer>

Once done you can set the property value via -J command-line argument like:

jmeter -JThroughput=12345 -n -t test.jmx -l result.jtl

More information:

  • Configuring JMeter
  • Overriding Properties Via The Command Line
  • Apache JMeter Properties Customization Guide

本文标签: bashHow to set Jmeter constant throughput timer to JMX XML as user inputStack Overflow