Forum Discussion

ABCDEFG's avatar
ABCDEFG
Contributor
13 years ago

Property Transfer Between Test Cases

Hi,

Can someone let me know how can we transfer properties between Test Cases in soapUI?

soapUI.org more teaches about PT b/w test steps

Thanks -
soapUI Candidate

9 Replies

  • For JSON format, instead of XPath, usage of jsonslurper is recommended.
    An example to achieve this is as:

    import groovy.json.JsonSlurper
    def response = messageExchange.response.responseContent
    def slurper = new JsonSlurper()
    def json = slurper.parseText response

    def ExpectedResultMessage = context.expand( '${#TestCase#ResultMessage}' ).toString()
    log.info 'ExpectedResultMessage ' + ExpectedResultMessage
    log.info 'json response ' + json."nsms.Response"."nsms.msg"
    assert json."nsms.Response"."nsms.msg" == ExpectedResultMessage

    Hope it helps.

    Regards,
    Ankita
  • Hi,

    Add a property to test suite. This property can be shared b/w all the test cases of that test suite.
    The property value can be read/write from any test case of that suite.

    Regards,
    AnkitaT
    • Renuka's avatar
      Renuka
      Occasional Contributor

      Ankita, How to add property to test suite?

    • rbachu1's avatar
      rbachu1
      New Contributor

      I have same problem, I have added a property at TestSuite Level but still the test case 2 is getting NULL Value.

       

      ${TestSuiteDemo#TokenValue}

      I also used ${#TestSuiteDemo#TokenValue} but nouse.. only with in the testcase property transfer is working fine. 

       

      Will there be any settings to see and change.

       

      Thank you

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        Hi rbachu1,

         

        You are using incorrect syntax

         

        ${#TestSuite#TokenValue}

         

        use above one it will help you out.

         

  • Thank you Ankita T.

    It worked well. Appreciating your help.
    I would like to give your some star ratings, though I am new to this forum and i don't know how to do it.

    ^Regards
  • Sharath's avatar
    Sharath
    Occasional Contributor
    Hi all..

    I use JSON format for the request and response for a Web Test case. So how would u use XPATH in this? Does XPATH work for JSON? I m a Novice, excuse if this is silly.

    Now..

    I wanna append the values returned from a response of a HTTP Request test step, to be a part of an endpoint of another HTTP Request test step. I tried by selecting "Endpoint" as my target but its replacing the complete end point. I need to append only the value. Help me out or list the steps to do this..

    I tried, to select a HTTP Test step as a source and select the property as the value from Response, then set another HTTP Test step as the target with its endpoint as the target property.

    What i need is, juz append the value from the source as a part of the endpoint, say www.google.com/{the property}

    How to do this? Is it possible in soapUI? If so, pls let me know the steps!
  • Sharath's avatar
    Sharath
    Occasional Contributor
    ankitaT wrote:
    For JSON format, instead of XPath, usage of jsonslurper is recommended.
    An example to achieve this is as:

    import groovy.json.JsonSlurper
    def response = messageExchange.response.responseContent
    def slurper = new JsonSlurper()
    def json = slurper.parseText response

    def ExpectedResultMessage = context.expand( '${#TestCase#ResultMessage}' ).toString()
    log.info 'ExpectedResultMessage ' + ExpectedResultMessage
    log.info 'json response ' + json."nsms.Response"."nsms.msg"
    assert json."nsms.Response"."nsms.msg" == ExpectedResultMessage

    Hope it helps.

    Regards,
    Ankita


    Hi Ankita.. Let me give you the scenario and the steps I've tried to make things work.

    Scenario: I should maintain a id throughout the test suite which contains 10 or more Test cases. The ID which I get on executing the first Test case, should be passed as a part of the endpoint for the next coming test cases, say wwww.google.com/{id}

    I tried: Creating the test suite and test cases, then adding HTTP Test request test step for each test cases. And then, after the test case has finished executing, the response is written to a xml file by using a Groovy script as a test step. BTW both the request and response are in JSON format not in XML. After writing the response to a file, I use another script to read the response from the file, and parse the JSON content to get only the value I need. Then I added the parameter to the endpoint for the next Test step, say http://www.google.com/$id. However, this failed!

    And I tried your code but its showing some error and it is "No property found:json"

    Now, how to pass this value as a part of the next test step's endpoint?
  • If I am getting the scenario correctly, here is a solution I can offer.

    make your endpoint url as a variable taken from project/suite property as in
    ${#Project#PIEndpointURL_REST}

    Then, when u capture that id value in variable, define another string variable, and append this id. eg:
    def url = context.expand(' ${#Project#PIEndpointURL_REST}')
    def temp = url + id
    log.info temp

    Now as the last step, using groovy script, write this new value back to the project/suite property which is used as endpoint url. Like if u r defining the URl as a testsuite prop, then:

    def ts = testRunner.testCase.testSuite.project.testSuites[<yourTestSuiteName>]
    tc.setPropertyValue("PIEndpointURL_REST", temp)

    Now next json request will take this newly written url with id as its endpoint.
    Let me know if it helps.
    All the best

    Regards,
    Ankita