我在操作Jmeter jtl报告文件时遇到了一项具有挑战性的任务。基本思想是从jtl中删除XML格式的最终报告不需要的不需要的记录(beanshell采样器等)。因此,我试图找到解决方案来删除包含 ctrlSampler 字符串的示例标记。
尝试使用此帖子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>
由于
答案 0 :(得分: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">
删除包含sample和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">
答案 1 :(得分:0)
出于兴趣,为什么不能只使用Filter Results Tool,它有--exclude-label-regex
选项,因此您可以过滤不需要的采样器。
可以使用JMeter Plugins Manager或manually
安装该插件成功安装后,您会在JMeter&#34; bin&#34;中找到FilterResults.sh
。夹