我被困在操縱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("noExecFailures","true");
f = new FileOutputStream("/opt/jmeter_test/execResult.property");
p = new PrintStream(f);
this.interpreter.setOut(p);
print("noExecFailures=" + vars.get("noExecFailures"));
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">{
"headers": {
"messageId": "5e5beb41-9cf0-4ef2-b678-7f47323b1b27"
},
"payload": {
"qualifier": "com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest",
"brandName": "playtech32001",
"context": {
"sessionContext": {
"clientType": "casino",
"clientPlatform": "download"
},
"clientVersion": "1",
"languageCode": "EN"
},
"urlTypeList": [
"cashier",
"cashier_ext",
"myAccount"
]
}
}</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">{
"headers": {
"messageId": "edcf182a-82a4-4649-9e4b-b586e95fa26c"
},
"payload": {
"qualifier": "com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest",
"brandName": "playtech32001",
"context": {
"sessionContext": {
"clientType": "casino",
"clientPlatform": "download"
},
"clientVersion": "1",
"languageCode": "EN"
},
"urlTypeList": [
"cashier",
"cashier_ext",
"myAccount"
]
}
}</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">{
"headers": {
"messageId": "5e5beb41-9cf0-4ef2-b678-7f47323b1b27"
},
"payload": {
"qualifier": "com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest",
"brandName": "playtech32001",
"context": {
"sessionContext": {
"clientType": "casino",
"clientPlatform": "download"
},
"clientVersion": "1",
"languageCode": "EN"
},
"urlTypeList": [
"cashier",
"cashier_ext",
"myAccount"
]
}
}</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">{
"headers": {
"messageId": "edcf182a-82a4-4649-9e4b-b586e95fa26c"
},
"payload": {
"qualifier": "com.playtech.ums.clientapi.notification.GetGlobalUrlsRequest",
"brandName": "playtech32001",
"context": {
"sessionContext": {
"clientType": "casino",
"clientPlatform": "download"
},
"clientVersion": "1",
"languageCode": "EN"
},
"urlTypeList": [
"cashier",
"cashier_ext",
"myAccount"
]
}
}</samplerData>
</sample>
</testResults>
感謝
感謝VIPIN, 找到
FilterResults.sh
安裝 其實我需要取出樣品標籤如果匹配到字符串標準ctrlSampler,不只是行 –