将变量传输到 TestStep SOAPUI

Transfer variable to TestStep SOAPUI

我正在尝试使用 groovy 脚本创建一个变量,然后在后续步骤中将其传输到 SOAP 请求。

这是我的 groovy 脚本 - 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 Add) 我尝试以这种方式使用变量(按照建议 ):

<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&amp; 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>

我不知道我做错了什么。有人可以帮忙吗?

解决方案与链接问题中的解决方案略有不同。我这样修改了脚本:

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>