inn jmeter,在具有多个同名标签的xml响应中,如何验证标签中存在的每个值在Jmeter上是否彼此不同。我附加了必须验证的响应。此代码包含2的描述优惠,但这个数字可以在0-10之间变化。我想对“msgid”进行一次唯一的检查(即响应中没有msgid值相同),并且还给出了msgid标记在响应中重复的次数。
enter code here <offers>
<number xsi:nil="true"/>
<number>
<amrit>S</amrit>
<interestedFlag>Y</interestedFlag>
<msgid>145983</msgid>
<msisdn xsi:nil="true"/>
<offerIndex>1</offerIndex>
<msgtext>Rs115=225 </msgtext>
<onlineFulfilmentFlag>Y</onlineFulfilmentFlag>
<orderId xsi:nil="true"/>
<otherSearchInfo>
<number>
<key>START_DATE</key>
<value>2016-09-16 11:28:46.921455</value>
</number>
<number>
<key>END_DATE</key>
<value>2017-08-03 00:00:00.0</value>
</number>
<number>
<key>OFFER_CATEGORY</key>
<value>Others</value>
</number>
</otherSearchInfo>
<price>115</price>
<shortDesc>115=225Loc+STD M,28D</shortDesc>
<subscriptionStatus>P</subscriptionStatus>
</number>
<number>
<amrit>O</amrit>
<interestedFlag>Y</interestedFlag>
<msgid>143429</msgid>
<msisdn xsi:nil="true"/>
<msgid>2803708</msgid>
<offerIndex>2</offerIndex>
<msgtext>Rs306=Rs306 Full</msgtext>
<onlineFulfilmentFlag>Y</onlineFulfilmentFlag>
<orderId xsi:nil="true"/>
<otherSearchInfo>
<number>
<key>START_DATE</key>
<value>2016-09-16 11:28:46.921455</value>
</number>
<number>
<key>END_DATE</key>
<value>2017-08-03 00:00:00.0</value>
</number>
<number>
<key>OFFER_CATEGORY</key>
<value>Combo</value>
</number>
</otherSearchInfo>
<price>306</price>
<shortDesc>Rs306=306TT(Ultd Val)</shortDesc>
<subscriptionStatus>P</subscriptionStatus>
</number>
<number>
<amrit>O</amrit>
<interestedFlag>Y</interestedFlag>
<msgid>145022</msgid>
<msisdn xsi:nil="true"/>
<msgid>2800482</msgid>
<msgtext>Rs110=Rs110 Full</msgtext>
<onlineFulfilmentFlag>Y</onlineFulfilmentFlag>
<orderId xsi:nil="true"/>
<otherSearchInfo>
<number>
<key>START_DATE</key>
<value>2016-09-16 11:28:46.921455</value>
</number>
<number>
<key>END_DATE</key>
<value>2017-08-03 00:00:00.0</value>
</number>
<number>
<key>OFFER_CATEGORY</key>
<value>Others</value>
</number>
</otherSearchInfo>
<price>110</price>
<shortDesc>Rs110=Rs110 FTT, ULTD</shortDesc>
<subscriptionStatus>P</subscriptionStatus>
</number>
答案 0 :(得分:0)
你可以使用JSR223 Assertion
一举两得将以下代码放入“脚本”区域:
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.collections.Predicate
def response = prev.getResponseDataAsString()
def xml = new XmlSlurper().parseText(response)
def msgids = xml."**".findAll { node ->
node.name() == "msgid"
}
msgids.each { msgid ->
int msgidCount = CollectionUtils.countMatches(msgids, new Predicate() {
boolean evaluate(Object input) {
return (input.equals(msgid));
}
})
log.info("Message ID: " + msgid + " count: " + msgidCount)
if (msgidCount > 1) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage("Message ID " + msgid + " occurred " + msgidCount + " times")
}
}
log.info("msgid count: " + msgids.size())
参考文献: