Jmeter xpath提取器不为有效的Xpath提供节点值

时间:2014-02-10 21:04:57

标签: javascript xml soap xpath jmeter

我正在使用Xpath Extractor从XML响应中找出节点值,但每次执行时Jmeter都会抛出错误,并出现以下错误:

  

jmeter.extractor.XPathExtractor:处理时发生TransformerException   ((// * [local-name()='RequestID'])[2] / text()) - 1

Jmeter中使用的xpath表达式:(//*[local-name() = 'RequestID'])[2]/text()

我在线检查了我的xpath表达式并且它有效并返回了预期的值。不确定jmeter有什么问题。

这是xml:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<urn1:ServiceControl xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">
<urn1:EmergencyRequestIndicator>true</urn1:EmergencyRequestIndicator>
<urn1:VersionID>1.0</urn1:VersionID>
<urn1:LanguageCode type="Advisor">en-US</urn1:LanguageCode>
<urn1:LanguageCode type="Subscriber">en-US</urn1:LanguageCode>
<urn1:ApplicationID>GAA</urn1:ApplicationID>
<urn1:LogicalID>W2DZD0Y06</urn1:LogicalID>
<urn1:ComponentID>GAA-ocsComponent</urn1:ComponentID>
<urn1:ReferenceID>CorrelationId</urn1:ReferenceID>
<urn1:SentTimeStamp>2010-04-23T14:27:10Z</urn1:SentTimeStamp>
<urn1:MessageType>ocsMessageType</urn1:MessageType>
<urn1:ChannelID>GAA</urn1:ChannelID>
<urn1:TaskID>ocsTask</urn1:TaskID>
<urn1:Environment>4.0</urn1:Environment>
<urn1:BODID>GAA-CorrelationId</urn1:BODID>
<urn1:Asynchronous>
<urn1:TimeToLive xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">10</urn1:TimeToLive>
<urn1:PassThroughData xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">
<urn1:Key xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">1</urn1:Key>
<urn1:Value xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">10</urn1:Value>
</urn1:PassThroughData>
<urn1:ExpectedResponseTime xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">30</urn1:ExpectedResponseTime>
<urn1:RequestID xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">100</urn1:RequestID>
<urn1:RetryStrategy xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">
<urn1:Name xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">RetryName</urn1:Name>
<urn1:LongTermRetryIndicator xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">false</urn1:LongTermRetryIndicator>
<urn1:ResponseRequiredOnErrorPoolMoveIndicator xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">true</urn1:ResponseRequiredOnErrorPoolMoveIndicator>
</urn1:RetryStrategy>
<urn1:ReplyRequiredIndicator xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">true</urn1:ReplyRequiredIndicator>
<urn1:ReplyToMessageID xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">1000</urn1:ReplyToMessageID>
<urn1:CallbackURI xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">urn1:www:com</urn1:CallbackURI>
<urn1:FaultURI xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">urn1:www:com</urn1:FaultURI>
<urn1:ProcessingModes xmlns:urn1="urn:com:sample:global:common:schema:ServiceControl:2">ProcessingMode</urn1:ProcessingModes>
</urn1:Asynchronous>
<urn1:Synchronous/>
</urn1:ServiceControl>
</S:Header>
<S:Body>
<ns2:ServiceRequestReference xmlns="urn:com:sample:ocs:common:schema:AutoTask:11" xmlns:ns10="urn:com:sample:global:common:schema:CallContext:2" xmlns:ns11="urn:com:sample:ocs:common:schema:ServiceFault:11" xmlns:ns12="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns13="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns14="http://www.w3.org/2000/09/xmldsig#" xmlns:ns15="urn:com:sample:global:common:schema:ServiceControl:2" xmlns:ns2="urn:com:sample:ocs:common:schema:CommonTypes:11" xmlns:ns3="urn:com:sample:ocs:common:schema:AutoInformation:11" xmlns:ns4="urn:com:sample:ocs:common:schema:UnitConfiguration:11" xmlns:ns5="urn:com:sample:ocs:common:schema:SubscriberRequest:11" xmlns:ns6="urn:com:sample:ocs:common:schema:ElectricAuto:11" xmlns:ns7="urn:com:sample:ocs:common:schema:EmergencyRequest:11" xmlns:ns8="urn:com:sample:ocs:common:schema:AutoRequest:11" xmlns:ns9="urn:com:sample:ocs:common:schema:AutoConnection:11">
<ns2:RequestID>2648331</ns2:RequestID>
<ns2:isProcessingAnotherRequest>false</ns2:isProcessingAnotherRequest>
<ns2:estimatedProcessingTime>0</ns2:estimatedProcessingTime>
</ns2:ServiceRequestReference>
</S:Body>
</S:Envelope>

1 个答案:

答案 0 :(得分:0)

您可以使用Beanshell Post Processor

从变量中减去1

假设您在XPath Extractor中使用RequestID作为参考名称,并且正在使用XPath获取RequestID

(//*[local-name() = 'RequestID'])[2]/text()

或     // NS2:请求ID /文本()

Next Beanshell代码将允许您操作变量

int requestId = Integer.parseInt(vars.get("RequestID"));
requestId = requestId--;
vars.put("RequestID", String.valueOf(requestId));