Forum Discussion

Anson1000's avatar
Anson1000
Occasional Contributor
7 years ago
Solved

How to get response property value and use it as next step input

Version SoapUI 5.3 

 

  1. The first step Get country by country code (I input “in”, and I should get country name “India”)
  2. I want to user the country name “India” as input country name for the second step

How do I do it with groovy

 

I try the following code, but it is not work

 

Get value from the first steps

 

def responseCountry = testRunner.testCase.testSteps['GetCountryByCountryCode'].getPropertyValue("Name")

 

Set responseCountry as property in second steps 

                

 

  • Just FYI there's no need to use Groovy, a regular Property Transfer will work just as well.

     

    Source (step): GetCountryByCountryCode
    Property: Response
    Path language: XPath
    Expression:

    (saxon:parse(//*:GetCountryByCountryCodeResult))//Table[1]/name

    or just

    (saxon:parse(//*:GetCountryByCountryCodeResult))//name

    (it seems that saxon picks the 1st matching node by default)


    Target: The test step where you need to use the "India" value
    Property: Request
    Path language: XPath

    Expression: An XPath expression for the target request field. For example, if you want to use the "India" value in the GetCurrencyByCountry operation that uses this request body

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET">
       <soap:Header/>
       <soap:Body>
          <web:GetCurrencyByCountry>
             <web:CountryName>India</web:CountryName>
          </web:GetCurrencyByCountry>
       </soap:Body>
    </soap:Envelope>

    the request XPath expression would be

    //*:CountryName

     

    I attached a sample project to demonstrate the above.

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Just FYI there's no need to use Groovy, a regular Property Transfer will work just as well.

     

    Source (step): GetCountryByCountryCode
    Property: Response
    Path language: XPath
    Expression:

    (saxon:parse(//*:GetCountryByCountryCodeResult))//Table[1]/name

    or just

    (saxon:parse(//*:GetCountryByCountryCodeResult))//name

    (it seems that saxon picks the 1st matching node by default)


    Target: The test step where you need to use the "India" value
    Property: Request
    Path language: XPath

    Expression: An XPath expression for the target request field. For example, if you want to use the "India" value in the GetCurrencyByCountry operation that uses this request body

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET">
       <soap:Header/>
       <soap:Body>
          <web:GetCurrencyByCountry>
             <web:CountryName>India</web:CountryName>
          </web:GetCurrencyByCountry>
       </soap:Body>
    </soap:Envelope>

    the request XPath expression would be

    //*:CountryName

     

    I attached a sample project to demonstrate the above.

    • Anson1000's avatar
      Anson1000
      Occasional Contributor

      Hi Helen,

       

      Thank you! It is easy solution for it

  • nmrao's avatar
    nmrao
    Champion Level 3

    Looks like this question is also posted here

     

    There is no need to have an additional groovy step. Instead add a Script Assertion for the first request test step

     

     

    //Check if there is repose
    assert context.response, 'Response is empty or null'
    def lookpcode = context.expand('${#TestCase#CountryCode}')
    def dataSet = new XmlSlurper().parseText(context.response).'**'.find{ it.name() == 'GetCountryByCountryCodeResult')} as String
    def countryName = new XmlSlurper().parseText(dataSet).'**'.find{ it.name() == 'countrycode' && it == lookpcode)}.parent().name.text()
    log.info "Country name is ${countryName} where code is ${lookpcode}"
    assert countryName, 'Country name empty or null'
    context.testCase.setPropertyValue('COUNTRY_NAME', countryName)

    In the next step, use property expansion where you needed the country name i.e., ${#TestCase#COUNTRY_NAME}