2017-03-01 89 views
0

我被困在操縱Jmeter jtl報告文件的一項具有挑戰性的任務中。基本思路是從XML格式的jtl中刪除不需要的最終報告所不需要的記錄(beanshell採樣器等)。所以,我試圖找到解決方案,以刪除那些樣本標籤包含ctrlSampler字符串。在Linux控制檯中從XML中刪除標記內容

嘗試使用此線程Delete nodes in xml if they contain certain text using sed但沒有成功

gawk -v IGNORECASE=1 '{ p = 1 } /<sample/{ t = $0; while (getline > 0) { t = t ORS $0; if (ctrlSampler) p = 0; if (/<\/sample>/) break } $0 = t } p' sourceJtl > targetJtl 

這裏的解決方案是樣品JTL

<?xml version="1.0" encoding="UTF-8"?> 
<testResults version="1.2"> 
<sample t="15" lt="0" ts="1488375720156" s="true" lb="ctrlSampler - fWrite - reset noExecFailures variable" rc="200" rm="OK" tn="setUp prereqs 1-1" dt="text" by="0"> 
    <responseHeader class="java.lang.String"></responseHeader> 
    <requestHeader class="java.lang.String"></requestHeader> 
    <responseData class="java.lang.String"></responseData> 
    <samplerData class="java.lang.String">  boolean noExecFailures; 
     vars.put(&quot;noExecFailures&quot;,&quot;true&quot;); 

    f = new FileOutputStream(&quot;/opt/jmeter_test/execResult.property&quot;); 
    p = new PrintStream(f); 
    this.interpreter.setOut(p); 
    print(&quot;noExecFailures=&quot; + vars.get(&quot;noExecFailures&quot;)); 
    f.close(); 
    </samplerData> 
</sample> 
<sample t="21" lt="0" ts="1488375720648" s="true" lb="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1::Notification::GetGlobalUrlsRequest" rc="200" rm="" tn="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1" dt="" by="598"> 
    <assertionResult> 
    <name>Response Assertion - Verify success response</name> 
    <failure>false</failure> 
    <error>false</error> 
    </assertionResult> 
    <assertionResult> 
    <name>Response Assertion - Verify response specific params</name> 
    <failure>false</failure> 
    <error>false</error> 
    </assertionResult> 
    <responseHeader class="java.lang.String"></responseHeader> 
    <requestHeader class="java.lang.String"></requestHeader> 
    <responseData class="java.lang.String"/> 
    <samplerData class="java.lang.String">{ 
    &quot;headers&quot;: { 
     &quot;messageId&quot;: &quot;5e5beb41-9cf0-4ef2-b678-7f47323b1b27&quot; 
    }, 
    &quot;payload&quot;: { 
     &quot;qualifier&quot;: &quot;com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest&quot;, 
     &quot;brandName&quot;: &quot;playtech32001&quot;, 
     &quot;context&quot;: { 
      &quot;sessionContext&quot;: { 
       &quot;clientType&quot;: &quot;casino&quot;, 
       &quot;clientPlatform&quot;: &quot;download&quot; 
      }, 
      &quot;clientVersion&quot;: &quot;1&quot;, 
      &quot;languageCode&quot;: &quot;EN&quot; 
     }, 
     &quot;urlTypeList&quot;: [ 
      &quot;cashier&quot;, 
      &quot;cashier_ext&quot;, 
      &quot;myAccount&quot; 
     ] 
    } 
}</samplerData> 
</sample> 
<sample t="7" lt="0" ts="1488375720706" s="false" lb="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1::Notification::GetGlobalUrlsRequest" rc="200" rm="" tn="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1" dt="" by="598"> 
    <assertionResult> 
    <name>Response Assertion - Verify success response</name> 
    <failure>false</failure> 
    <error>false</error> 
    </assertionResult> 
    <assertionResult> 
    <name>Response Assertion - Verify response specific params</name> 
    <failure>true</failure> 
    <error>false</error> 
    <failureMessage>Test failed: text expected to contain /INJECT FAILIRE/</failureMessage> 
    </assertionResult> 
    <responseHeader class="java.lang.String"></responseHeader> 
    <requestHeader class="java.lang.String"></requestHeader> 
    <responseData class="java.lang.String"/> 
    <samplerData class="java.lang.String">{ 
    &quot;headers&quot;: { 
     &quot;messageId&quot;: &quot;edcf182a-82a4-4649-9e4b-b586e95fa26c&quot; 
    }, 
    &quot;payload&quot;: { 
     &quot;qualifier&quot;: &quot;com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest&quot;, 
     &quot;brandName&quot;: &quot;playtech32001&quot;, 
     &quot;context&quot;: { 
      &quot;sessionContext&quot;: { 
       &quot;clientType&quot;: &quot;casino&quot;, 
       &quot;clientPlatform&quot;: &quot;download&quot; 
      }, 
      &quot;clientVersion&quot;: &quot;1&quot;, 
      &quot;languageCode&quot;: &quot;EN&quot; 
     }, 
     &quot;urlTypeList&quot;: [ 
      &quot;cashier&quot;, 
      &quot;cashier_ext&quot;, 
      &quot;myAccount&quot; 
     ] 
    } 
}</samplerData> 
</sample> 

</testResults> 

結果所需

<?xml version="1.0" encoding="UTF-8"?> 
    <testResults version="1.2"> 
    <sample t="21" lt="0" ts="1488375720648" s="true" lb="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1::Notification::GetGlobalUrlsRequest" rc="200" rm="" tn="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1" dt="" by="598"> 
     <assertionResult> 
     <name>Response Assertion - Verify success response</name> 
     <failure>false</failure> 
     <error>false</error> 
     </assertionResult> 
     <assertionResult> 
     <name>Response Assertion - Verify response specific params</name> 
     <failure>false</failure> 
     <error>false</error> 
     </assertionResult> 
     <responseHeader class="java.lang.String"></responseHeader> 
     <requestHeader class="java.lang.String"></requestHeader> 
     <responseData class="java.lang.String"/> 
     <samplerData class="java.lang.String">{ 
     &quot;headers&quot;: { 
      &quot;messageId&quot;: &quot;5e5beb41-9cf0-4ef2-b678-7f47323b1b27&quot; 
     }, 
     &quot;payload&quot;: { 
      &quot;qualifier&quot;: &quot;com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest&quot;, 
      &quot;brandName&quot;: &quot;playtech32001&quot;, 
      &quot;context&quot;: { 
       &quot;sessionContext&quot;: { 
        &quot;clientType&quot;: &quot;casino&quot;, 
        &quot;clientPlatform&quot;: &quot;download&quot; 
       }, 
       &quot;clientVersion&quot;: &quot;1&quot;, 
       &quot;languageCode&quot;: &quot;EN&quot; 
      }, 
      &quot;urlTypeList&quot;: [ 
       &quot;cashier&quot;, 
       &quot;cashier_ext&quot;, 
       &quot;myAccount&quot; 
      ] 
     } 
    }</samplerData> 
    </sample> 
    <sample t="7" lt="0" ts="1488375720706" s="false" lb="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1::Notification::GetGlobalUrlsRequest" rc="200" rm="" tn="[TP7][IMS][TEST PLAYER REQUESTS SUCCESS FLOW] 2-1" dt="" by="598"> 
     <assertionResult> 
     <name>Response Assertion - Verify success response</name> 
     <failure>false</failure> 
     <error>false</error> 
     </assertionResult> 
     <assertionResult> 
     <name>Response Assertion - Verify response specific params</name> 
     <failure>true</failure> 
     <error>false</error> 
     <failureMessage>Test failed: text expected to contain /INJECT FAILIRE/</failureMessage> 
     </assertionResult> 
     <responseHeader class="java.lang.String"></responseHeader> 
     <requestHeader class="java.lang.String"></requestHeader> 
     <responseData class="java.lang.String"/> 
     <samplerData class="java.lang.String">{ 
     &quot;headers&quot;: { 
      &quot;messageId&quot;: &quot;edcf182a-82a4-4649-9e4b-b586e95fa26c&quot; 
     }, 
     &quot;payload&quot;: { 
      &quot;qualifier&quot;: &quot;com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest&quot;, 
      &quot;brandName&quot;: &quot;playtech32001&quot;, 
      &quot;context&quot;: { 
       &quot;sessionContext&quot;: { 
        &quot;clientType&quot;: &quot;casino&quot;, 
        &quot;clientPlatform&quot;: &quot;download&quot; 
       }, 
       &quot;clientVersion&quot;: &quot;1&quot;, 
       &quot;languageCode&quot;: &quot;EN&quot; 
      }, 
      &quot;urlTypeList&quot;: [ 
       &quot;cashier&quot;, 
       &quot;cashier_ext&quot;, 
       &quot;myAccount&quot; 
      ] 
     } 
    }</samplerData> 
    </sample> 

    </testResults> 

感謝

回答

0

試試這個 -

測試 -

sed -n '/sample/{/ctrlSampler/p}' f > f1 

cat f1 ##### Here we have only one record. 
<sample t="15" lt="0" ts="1488375720156" s="true" lb="ctrlSampler - fWrite - reset noExecFailures variable" rc="200" rm="OK" tn="setUp prereqs 1-1" dt="text" by="0"> 

刪除包含樣品和ctrlSampler行 -

sed '/sample/{/ctrlSampler/d}' f > f2 

diff f f2 
3d2 
< <sample t="15" lt="0" ts="1488375720156" s="true" lb="ctrlSampler - fWrite - reset noExecFailures variable" rc="200" rm="OK" tn="setUp prereqs 1-1" dt="text" by="0"> 
+0

感謝VIPIN, 找到FilterResults.sh安裝 其實我需要取出樣品標籤如果匹配到字符串標準ctrlSampler,不只是行 –

0

出於興趣,爲什麼你就不能使用Filter Results Tool,它有--exclude-label-regex選項,因此你將能夠過濾不需要的採樣器。

該插件可以使用JMeter Plugins Managermanually

JMeter Plugins Manager Filter Results Tool

成功安裝後,你會在JMeter的 「bin」 文件夾

+0

謝謝德米特里, 請,建議如何使用th在,似乎我沒有這樣做 FilterResults.bat --output-file testFilterResutls.jtl --input-file .. \ extras \ JMeterClientAPI_regression_autotest.jtl --save-as-xml true --exclude-label-正則表達式真正--exclude標籤「ctrlSampler」 這通過,但沒有記錄被刪除出文件,我假設我的排除標籤正則表達式不正確 –

+0

你應該使用[Perl5兼容正則表達式](https:/ /en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions),即類似'「。* ctrlSampler。*」'。請參閱JMeter用戶手冊的[正則表達式](http://jmeter.apache.org/usermanual/regular_expressions.html)章節,以防萬一[使用帶JMeter的RegEx(正則表達式提取器)](https://guide.blazemeter .com/hc/en-us/articles/207421325-Using-RegEx-Regular-Expression-Extractor-with-JMeter)瞭解更多詳情。 –

+0

嘗試使用此正則表達式,檢查了regex101.com,但沒有運氣 lb =「(ctrlSampler。*?)」。有什麼建議麼? –