2016-02-14 2 views
1

Я пытаюсь запустить jmx-скрипт с помощью java-кода. но когда я попытался запустить код, он показывает мне, что 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> 

вот мой TestPlan класс:

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) 

плз кто может сказать мне, что эта ошибка и как его решить? заранее заблаговременно

ответ

0

Вы пытались открыть файл jmx в jmeter? Проблема была в этой строке # 126.

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

Это должно быть

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

Просто любопытно - Почему вы хотите, чтобы запустить тест JMeter с помощью Java? Что вам нравится?

Вы можете использовать Ant/Maven для запуска тестов JMeter, если вы хотите запустить программно. Вы можете увидеть подробные шаги здесь: http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/

+0

это просто скопировать пасту problem.it на самом деле во втором формате у mention.and я попытался запустить с помощью JMeter. это работает. Но через java-код это не так. Я должен объединить его с графическим интерфейсом, поэтому я использую код Java –

+0

Привет, кажется, вы добавляете ссылку на веб-сайт, на котором есть подписки. Похоже, вы пытаетесь получить больше просмотров на сайте. Обратите внимание, что это может вызвать подозрение среди членов сообщества, что может привести к приостановке вашей учетной записи. См. Этот [ответ] (http://meta.stackoverflow.com/a/294124/4099593). Я пишу этот комментарий, чтобы предупредить вас заранее. С уважением. –

+0

@BhargavRao, ничего подобного. Это мой блог. Я просто хотел, чтобы OP знал, есть ли другие способы вызвать тест JMeter. Он не требует подписки/у меня нет рекламы. – vins

1

Я получил свою ошибку. Мне нужно загрузить jmx fie в сервисный метод SAve. строка 32 должна быть равна HashTree hash = SaveService.loadTree (файл); вместо HashTree хэш = новый HashTree (файл); .. спасибо вам

Смежные вопросы