我正在尝试使用常规脚本创建变量,然后在后续步骤中将其传输到SOAP请求。
这是我的常规脚本-TestStep InputVariables :
def nextStep = testRunner.testCase.getTestStepByName("Add")
def first = 88
def second = 12
def res = nextStep.run(testRunner, context)
log.info res
然后在SOAP步骤(TestStep 添加)中,我尝试以这种方式使用变量(如建议的here):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>"${#InputVariables#first}"</tem:intA>
<tem:intB>"${#InputVariables#second}"</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
但是它不起作用。这是我收到的回复:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (5, 33). ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Xml.XmlConvert.ToInt32(String s)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_Add()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
我不知道我在做什么错。有人可以帮忙吗?
答案 0 :(得分:2)
解决方案与链接的问题略有不同。我以这种方式修改了脚本:
def nextStep = testRunner.testCase.getTestStepByName("Add")
Integer first = 88
Integer second = 12
context.first = first
context.second = second
def res = nextStep.run(testRunner, context)
log.info res
和添加的步骤如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>${first}</tem:intA>
<tem:intB>${second}</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
仅此而已。我收到的回复没有错误:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AddResponse xmlns="http://tempuri.org/">
<AddResult>100</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>