2013-07-04 50 views
1

您能否告诉我如何每次运行线程时清除/重置由Simple Data Writer写入的csv文件? 当前每次运行线程时,都会将新结果追加到旧结果的末尾。我是新手,谢谢你的帮助。在jmeter中清除简单数据写入器的csv文件

代码

<?xml version="1.0" encoding="UTF-8"?> 
<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9 r1437961"> 
<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">true</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-1" 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">1371005294000</longProp> 
    <longProp name="ThreadGroup.end_time">1371005294000</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="GET Patient list" 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">http://sampleurl</stringProp> 
     <stringProp name="HTTPSampler.port"></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">http://sampleurl</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> 
     <AuthManager guiclass="AuthPanel" testclass="AuthManager" testname="HTTP Authorization Manager" enabled="true"> 
     <collectionProp name="AuthManager.auth_list"> 
      <elementProp name="" elementType="Authorization"> 
      <stringProp name="Authorization.url">http://sampurl</stringProp> 
      <stringProp name="Authorization.username">samp</stringProp> 
      <stringProp name="Authorization.password">samp</stringProp> 
      <stringProp name="Authorization.domain"></stringProp> 
      <stringProp name="Authorization.realm"></stringProp> 
      </elementProp> 
     </collectionProp> 
     </AuthManager> 
     <hashTree/> 
     <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor" enabled="true"> 
     <stringProp name="RegexExtractor.useHeaders">false</stringProp> 
     <stringProp name="RegexExtractor.refname">Ary</stringProp> 
     <stringProp name="RegexExtractor.regex">\[([^\]]+)\]</stringProp> 
     <stringProp name="RegexExtractor.template">$1$</stringProp> 
     <stringProp name="RegexExtractor.default"></stringProp> 
     <stringProp name="RegexExtractor.match_number">1</stringProp> 
     </RegexExtractor> 
     <hashTree/> 
     <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Parse ECN array" enabled="true"> 
     <stringProp name="RegexExtractor.useHeaders">false</stringProp> 
     <stringProp name="RegexExtractor.refname">vals</stringProp> 
     <stringProp name="RegexExtractor.regex">&quot;([^&quot;]+)&quot;</stringProp> 
     <stringProp name="RegexExtractor.template">$1$</stringProp> 
     <stringProp name="RegexExtractor.default"></stringProp> 
     <stringProp name="RegexExtractor.match_number">-1</stringProp> 
     <stringProp name="Scope.variable">PatientArray</stringProp> 
     <stringProp name="Sample.scope">variable</stringProp> 
     </RegexExtractor> 
     <hashTree/> 
    </hashTree> 
    <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="RegX output" enabled="true"> 
     <boolProp name="displayJMeterProperties">false</boolProp> 
     <boolProp name="displayJMeterVariables">true</boolProp> 
     <boolProp name="displaySystemProperties">false</boolProp> 
    </DebugSampler> 
    <hashTree/> 
    <ForeachController guiclass="ForeachControlPanel" testclass="ForeachController" testname="ForEach Controller" enabled="true"> 
     <stringProp name="ForeachController.inputVal">vals</stringProp> 
     <stringProp name="ForeachController.returnVal">userid</stringProp> 
     <boolProp name="ForeachController.useSeparator">true</boolProp> 
    </ForeachController> 
    <hashTree> 
     <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="${userid}" enabled="true"> 
     <boolProp name="displayJMeterProperties">true</boolProp> 
     <boolProp name="displayJMeterVariables">true</boolProp> 
     <boolProp name="displaySystemProperties">false</boolProp> 
     </DebugSampler> 
     <hashTree> 
     <ResultCollector guiclass="SimpleDataWriter" testclass="ResultCollector" testname="Simple Data Writer" enabled="true"> 
      <boolProp name="ResultCollector.error_logging">false</boolProp> 
      <objProp> 
      <name>saveConfig</name> 
      <value class="SampleSaveConfiguration"> 
       <time>false</time> 
       <latency>false</latency> 
       <timestamp>false</timestamp> 
       <success>false</success> 
       <label>true</label> 
       <code>false</code> 
       <message>false</message> 
       <threadName>false</threadName> 
       <dataType>false</dataType> 
       <encoding>false</encoding> 
       <assertions>false</assertions> 
       <subresults>false</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> 
      </value> 
      </objProp> 
      <stringProp name="filename">C:\Documents and Settings\valliammaim\My Documents\Downloads\apache-jmeter-2.9\apache-jmeter-2.9\bin\RegXoutput.csv</stringProp> 
     </ResultCollector> 
     <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> 
     </value> 
     </objProp> 
     <stringProp name="filename"></stringProp> 
    </ResultCollector> 
    <hashTree/> 
    <ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="Aggregate Report" 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>false</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>true</fieldNames> 
      <responseHeaders>false</responseHeaders> 
      <requestHeaders>false</requestHeaders> 
      <responseDataOnError>false</responseDataOnError> 
      <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> 
      <assertionsResultsToSave>0</assertionsResultsToSave> 
      <bytes>true</bytes> 
     </value> 
     </objProp> 
     <stringProp name="filename">C:\Documents and Settings\valliammaim\My Documents\Downloads\apache-jmeter-2.9\apache-jmeter-2.9\bin\report.csv</stringProp> 
     <boolProp name="useGroupName">true</boolProp> 
    </ResultCollector> 
    <hashTree/> 
    </hashTree> 
    <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group-2" 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">1372725732000</longProp> 
    <longProp name="ThreadGroup.end_time">1372725732000</longProp> 
    <boolProp name="ThreadGroup.scheduler">false</boolProp> 
    <stringProp name="ThreadGroup.duration"></stringProp> 
    <stringProp name="ThreadGroup.delay"></stringProp> 
    </ThreadGroup> 
    <hashTree> 
    <WhileController guiclass="WhileControllerGui" testclass="WhileController" testname="While Controller" enabled="true"> 
     <stringProp name="WhileController.condition">&quot;${userid}&quot; != &quot;&lt;EOF&gt;&quot;</stringProp> 
    </WhileController> 
    <hashTree> 
     <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> 
     <boolProp name="LoopController.continue_forever">true</boolProp> 
     <stringProp name="LoopController.loops">1</stringProp> 
     </LoopController> 
     <hashTree> 
     <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="GET Patient" 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">http://sampurl/${patientECN}</stringProp> 
      <stringProp name="HTTPSampler.port"></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">http://sampleurl/${patientECN}</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> 
      <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true"> 
      <stringProp name="ConstantTimer.delay">100</stringProp> 
      </ConstantTimer> 
      <hashTree/> 
      <AuthManager guiclass="AuthPanel" testclass="AuthManager" testname="HTTP Authorization Manager" enabled="true"> 
      <collectionProp name="AuthManager.auth_list"> 
       <elementProp name="" elementType="Authorization"> 
       <stringProp name="Authorization.url">http://sampurl/${userid}</stringProp> 
       <stringProp name="Authorization.username">sample</stringProp> 
       <stringProp name="Authorization.password">sample</stringProp> 
       <stringProp name="Authorization.domain"></stringProp> 
       <stringProp name="Authorization.realm"></stringProp> 
       </elementProp> 
      </collectionProp> 
      </AuthManager> 
      <hashTree/> 
     </hashTree> 
     </hashTree> 
     <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSV Data Set Config" enabled="true"> 
     <stringProp name="delimiter">,</stringProp> 
     <stringProp name="fileEncoding"></stringProp> 
     <stringProp name="filename">RegXoutput.csv</stringProp> 
     <boolProp name="quotedData">true</boolProp> 
     <boolProp name="recycle">false</boolProp> 
     <stringProp name="shareMode">All threads</stringProp> 
     <boolProp name="stopThread">true</boolProp> 
     <stringProp name="variableNames">userid</stringProp> 
     </CSVDataSet> 
     <hashTree/> 
    </hashTree> 
    <ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="Aggregate Report" 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> 
     </value> 
     </objProp> 
     <stringProp name="filename"></stringProp> 
    </ResultCollector> 
    <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> 
     </value> 
     </objProp> 
     <stringProp name="filename"></stringProp> 
    </ResultCollector> 
    <hashTree/> 
    </hashTree> 
</hashTree> 

+0

您能否显示用于打开/写入csv文件的代码? – rsp

+0

在上面的代码更新中,我使用一个简单的数据编写器来捕获我的输出。每次执行线程组时,我都要覆盖它。感谢你们对我的帮助。 – Sashi

+0

简单数据写入器没有可让您截断可惜的文件的属性。或者,你可以在文件名中加上一个时间戳,以确保在测试开始时它是空的(比如'RegXoutput $ {__time(yyyyMMdd-HHmm,)} .csv'),然后清理,或者使用BeanShell脚本截断文件。 – rsp

回答

2
  • 的*简单的数据录入有没有财产,让你截断这是一个遗憾的文件。或者,您可以在文件名中加上一个时间戳,以确保它在测试开始时为空(如RegXoutput $ {__time(yyyyMMdd-HHmm,)} .csv)并随后清理或使用BeanShell脚本截断文件。 * - RSP 3天前

  • 谢谢RSP时间戳的解决方案是这一问题的最佳替代品。