2016-02-14 30 views
1

我正在嘗試使用java代碼運行jmx腳本。但是當我試圖運行代碼時,它向我展示了testplan不存在。我在這裏檢查了這個問題/jmeter-could-not-find-the-testplan-class,我檢查了我的jmx文件。它被優先格式化。in jmeter:java.lang.RuntimeException:找不到TestPlan類

這裏是我的JMX文件:

<?xml version="1.0" encoding="UTF-8"?> 
<jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067"> 
    <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="first try" 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">1455186838000</longProp> 
     <longProp name="ThreadGroup.end_time">1455186838000</longProp> 
     <boolProp name="ThreadGroup.scheduler">false</boolProp> 
     <stringProp name="ThreadGroup.duration"></stringProp> 
     <stringProp name="ThreadGroup.delay"></stringProp> 
     </ThreadGroup> 
     <hashTree> 
     <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="speciality" enabled="true"> 
      <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
      <collectionProp name="Arguments.arguments"/> 
      </elementProp> 
      <stringProp name="HTTPSampler.domain">localhost</stringProp> 
      <stringProp name="HTTPSampler.port">8080</stringProp> 
      <stringProp name="HTTPSampler.connect_timeout"></stringProp> 
      <stringProp name="HTTPSampler.response_timeout"></stringProp> 
      <stringProp name="HTTPSampler.protocol"></stringProp> 
      <stringProp name="HTTPSampler.contentEncoding"></stringProp> 
      <stringProp name="HTTPSampler.path">JmeterJson/speciality</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> 
     </HTTPSamplerProxy> 
     <hashTree> 
      <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor" enabled="true"> 
      <stringProp name="RegexExtractor.useHeaders">false</stringProp> 
      <stringProp name="RegexExtractor.refname">names</stringProp> 
      <stringProp name="RegexExtractor.regex">(dentist|cardio)</stringProp> 
      <stringProp name="RegexExtractor.template">$1$</stringProp> 
      <stringProp name="RegexExtractor.default">NONE</stringProp> 
      <stringProp name="RegexExtractor.match_number">-1</stringProp> 
      <stringProp name="Sample.scope">all</stringProp> 
      </RegexExtractor> 
      <hashTree/> 
      <DebugPostProcessor guiclass="TestBeanGUI" testclass="DebugPostProcessor" testname="Debug PostProcessor" enabled="true"> 
      <boolProp name="displayJMeterProperties">false</boolProp> 
      <boolProp name="displayJMeterVariables">true</boolProp> 
      <boolProp name="displaySamplerProperties">true</boolProp> 
      <boolProp name="displaySystemProperties">false</boolProp> 
      </DebugPostProcessor> 
      <hashTree/> 
     </hashTree> 
     <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller" enabled="true"> 
      <stringProp name="ForeachController.inputVal">names</stringProp> 
      <stringProp name="ForeachController.returnVal">name</stringProp> 
      <boolProp name="ForeachController.useSeparator">true</boolProp> 
     </ForeachController> 
     <hashTree> 
      <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="${name}" enabled="true"> 
      <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
       <collectionProp name="Arguments.arguments"/> 
      </elementProp> 
      <stringProp name="HTTPSampler.domain">localhost</stringProp> 
      <stringProp name="HTTPSampler.port">8080</stringProp> 
      <stringProp name="HTTPSampler.connect_timeout"></stringProp> 
      <stringProp name="HTTPSampler.response_timeout"></stringProp> 
      <stringProp name="HTTPSampler.protocol"></stringProp> 
      <stringProp name="HTTPSampler.contentEncoding"></stringProp> 
      <stringProp name="HTTPSampler.path">JmeterJson/names?speciality=${name}</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> 
      </HTTPSamplerProxy> 
      <hashTree> 
      <DebugPostProcessor guiclass="TestBeanGUI" testclass="DebugPostProcessor" testname="Debug PostProcessor" enabled="true"> 
       <boolProp name="displayJMeterProperties">false</boolProp> 
       <boolProp name="displayJMeterVariables">true</boolProp> 
       <boolProp name="displaySamplerProperties">true</boolProp> 
       <boolProp name="displaySystemProperties">false</boolProp> 
      </DebugPostProcessor> 
      <hashTree/> 
      <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor" enabled="true"> 
       <stringProp name="RegexExtractor.useHeaders">false</stringProp> 
       <stringProp name="RegexExtractor.refname">times</stringProp> 
       <stringProp name="RegexExtractor.regex">(deepak|kk|kumar|bs)</stringProp> 
       <stringProp name="RegexExtractor.template">$1$</stringProp> 
       <stringProp name="RegexExtractor.default">NONE</stringProp> 
       <stringProp name="RegexExtractor.match_number">-1</stringProp> 
      </RegexExtractor> 
      <hashTree/> 
      </hashTree> 
      <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller" enabled="true"> 
      <stringProp name="ForeachController.inputVal">times</stringProp> 
      <stringProp name="ForeachController.returnVal">time</stringProp> 
      <boolProp name="ForeachController.useSeparator">true</boolProp> 
      </ForeachController> 
      <hashTree> 
      <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="${time}" enabled="true"> 
       <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
       <collectionProp name="Arguments.arguments"/> 
       </elementProp> 
       <stringProp name="HTTPSampler.domain">localhost</stringProp> 
       <stringProp name="HTTPSampler.port">8080</stringProp> 
       <stringProp name="HTTPSampler.connect_timeout"></stringProp> 
       <stringProp name="HTTPSampler.response_timeout"></stringProp> 
       <stringProp name="HTTPSampler.protocol"></stringProp> 
       <stringProp name="HTTPSampler.contentEncoding"></stringProp> 
       <stringProp name="HTTPSampler.path">JmeterJson/appointments?things=${time}</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> 
      </HTTPSamplerProxy> 
      <hashTree> 
       <DebugPostProcessor guiclass="TestBeanGUI" testclass="DebugPostProcessor" testname="Debug PostProcessor" enabled="true"> 
       <boolProp name="displayJMeterProperties">false</boolProp> 
       <boolProp name="displayJMeterVariables">true</boolProp> 
       <boolProp name="displaySamplerProperties">true</boolProp> 
       <boolProp name="displaySystemProperties">false</boolProp> 
       </DebugPostProcessor> 
       <hashTree/> 
      </hashTree> 
      </hashTree> 
     </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>false</xml> 
       <fieldNames>false</fieldNames> 
       <responseHeaders>false</responseHeaders> 
       <requestHeaders>false</requestHeaders> 
       <responseDataOnError>false</responseDataOnError> 
       <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> 
       <assertionsResultsToSave>0</assertionsResultsToSave> 
       <bytes>true</bytes> 
       <threadCounts>true</threadCounts> 
      </value> 
      </objProp> 
      <stringProp name="filename"></stringProp> 
     </ResultCollector> 
     <hashTree/> 
     <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set Config" enabled="true"> 
      <stringProp name="filename">specialist</stringProp> 
      <stringProp name="fileEncoding"></stringProp> 
      <stringProp name="variableNames"></stringProp> 
      <stringProp name="delimiter">,</stringProp> 
      <boolProp name="quotedData">false</boolProp> 
      <boolProp name="recycle">true</boolProp> 
      <boolProp name="stopThread">false</boolProp> 
      <stringProp name="shareMode">shareMode.all</stringProp> 
     </CSVDataSet> 
     <hashTree/> 
     </hashTree> 
    </hashTree> 
    </hashTree> 
</jmeterTestPlan> 

這裏是我的測試計劃類:

package main.java.test; 

import java.io.FileInputStream; 
import java.io.IOException; 

import org.apache.jmeter.engine.StandardJMeterEngine; 
import org.apache.jmeter.save.SaveService; 
import org.apache.jmeter.util.JMeterUtils; 
import org.apache.jorphan.collections.HashTree; 

public class TestPlan { 

public static void main(String[] args) { 


    StandardJMeterEngine jmeter=new StandardJMeterEngine(); 

    JMeterUtils.loadJMeterProperties("/Users/vihang_shah01/Desktop/apache-jmeter-2.13/bin/jmeter.properties"); 
    JMeterUtils.setJMeterHome("/Users/vihang_shah01/Desktop/apache-jmeter-2.13"); 
    JMeterUtils.initLogging(); 
    JMeterUtils.initLocale(); 

    try { 
     SaveService.loadProperties(); 

     FileInputStream file=new FileInputStream("/Users/vihang_shah01/Desktop/apache-jmeter-2.13/bin/firstTry.jmx"); 

     HashTree hash=new HashTree(file); 

     file.close(); 

     jmeter.configure(hash); 
     jmeter.run(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 





} 





} 

這是我的例外:

Exception in thread "main" java.lang.RuntimeException: Could not find the TestPlan class! 
    at org.apache.jmeter.engine.StandardJMeterEngine.configure(StandardJMeterEngine.java:171) 
    at main.java.com.infy.test.TestPlan.main(TestPlan.java:32) 

PLZ誰能告訴我這是什麼錯誤以及如何解決它?預先感謝

回答

0

您是否嘗試在jmeter中打開jmx文件? 問題在於這條線#126。

  <stringPropname="HTTPSampler.path">JmeterJson/appointments?things=${time}</stringProp> 

應該

  <stringProp name="HTTPSampler.path">JmeterJson/appointments?things=${time}</stringProp> 

只是好奇 - 爲什麼要運行使用Java的JMeter測試? 你喜歡做什麼?

如果要以編程方式運行,可以使用Ant/Maven運行JMeter測試。 您可以在此處看到詳細步驟:http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/

+0

它只是複製粘貼problem.it實際上是在ümention.and我試圖用JMeter來運行第二個格式。它的工作,但通過Java代碼它不是。我必須將它與GUI合併,所以我使用java代碼 –

+0

嗨,你似乎正在添加一個鏈接到訂閱的網站。它看起來像你試圖在網站上獲得更多的意見。請注意,這樣做可能會增加社區成員的懷疑,這可能會導致您的帳戶被暫停。請參閱此[答案](http://meta.stackoverflow.com/a/294124/4099593)。我正在寫這個評論,以提前警告你。問候。 –

+0

@BhargavRao,沒有那樣的。這是我的博客。我只是想讓OP知道是否有其他方法來調用JMeter測試。它不需要任何訂閱/我沒有任何廣告。 – vins

1

我弄錯了。我必須在SAve服務方法中加載jmx fie。行號32應該像HashTree hash = SaveService.loadTree(file);的 代替HashTree哈希=新HashTree(文件); ..謝謝