Передайте переменную в TestStep SOAPUI - PullRequest
0 голосов
/ 01 ноября 2018

Я пытаюсь использовать скрипт groovy для создания переменной, а затем перенести ее в запрос 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 Добавить ) я пытаюсь использовать переменные следующим образом (как предложено здесь ):

<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>

Я не знаю точно, что я делаю неправильно. Кто-нибудь может помочь?

1 Ответ

0 голосов
/ 01 ноября 2018

Решение было немного другим, чем в связанном вопросе. Я изменил скрипт так:

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>
...