Forum Discussion

Elsevier_-_OH_S's avatar
Elsevier_-_OH_S
Contributor
11 years ago

Geeting an object from Response

I have a response Node <ns2:abc>59a7-95408ae85419c802a54f5c573fd38ce5a39-dnW</ns2:abc>
i want to reffer this node and set it up at project level . I am using below script to reffer that its giving an error saying no such propert abc.Please let me know where i am wrong.
def testingAuthTokenMatch = String.valueOf(testRunner.testCase.getTestStepByName("Authenticate_User").httpRequest.responseContent["abc"]) =~ /\[(.*)\]/
  • I have a response Node <ns2:abc>59a7-95408ae85419c802a54f5c573fd38ce5a39-dnW</ns2:abc>
    i want to get value from this node from my one test response and set it up at project level as a property.This is a dynamic value so i want to run this everytime and use it in my test cases or test suits accessing it from project level.I created a property AToken at project level , value from abc tag would be set to that AToken. I am using below script to reffer that its giving an error saying no such propert abc.Please let me know where i am wrong.
    def Token = String.valueOf(testRunner.testCase.getTestStepByName("Authenticate_User").httpRequest.responseContent["abc"]) =~ /\[(.*)\]/
    def AToken = Token[0][1]
    testRunner.testCase.testSuite.project.setPropertyValue("AToken", AToken)
  • Hi,

    You can create a testcase level property for the node value.
    Here is the tips and tricks to get and set properties,
    http://www.soapui.org/Scripting-Propert ... properties

    And with point and click testing you can capture any value from responseAsXml,
    http://www.soapui.org/Working-with-soap ... sting.html

    On that request add Script Assertion,
    http://www.soapui.org/Functional-Testin ... tions.html

    //Right click > Get Data get the specific node from response,
    def value = context.expand( '${REST Test Request#ResponseAsXml#//GeocodeResponse[1]/result[1]/address_component[1]/long_name[1]}' )
    //Save it in a testcase property
    testRunner.testCase.setPropertyValue( "Testcase_property_name",value )


    You can refer the Test case property value again using property expansion (Right click > get data > Testcase > Property)

    context.expand( '${#TestCase#testcase_property_name}' )


    Thanks,
    Jeshtha
  • Well point and click approach failed i was doing it previously after refactoring my WSDL file....its kind of hardcoaded... when u refactor ur WSDL it wont change the version of WSDL comes with that xPath into that request field....and my 200 test cases failed ... we have several versions of WSDL for these test cases...i cant do this thing everytime....so i want to set it at project level ....we were able to do for this problem getting a header value and putting it at project level and using it into the request where ever we want. Below code worked for us while taking value from response header it worked fine.
    def TokenMatch = String.valueOf(testRunner.testCase.getTestStepByName("Send Request").httpRequest.response.responseHeaders["Token"]) =~ /\[(.*)\]/
    def AuthToken = TokenMatch[0][1]
    testRunner.testCase.testSuite.project.setPropertyValue("AuthToken", AuthToken)

    No we wnat same thing to do getting value from our response body but i dnt know what property to use for response body as we used responseHeaders. If jut want to know any property to use for getting value from response body, it will solve my purpose.
  • On that request add Script Assertion,
    http://www.soapui.org/Functional-Testin ... tions.html

    Code: Select all
    //Right click > Get Data get the specific node from response,
    def value = context.expand( '${REST Test Request#ResponseAsXml#//GeocodeResponse[1]/result[1]/address_component[1]/long_name[1]}' )
    //Save it in a testcase property
    testRunner.testCase.setPropertyValue( "Testcase_property_name",value )


    I am getting an error for this no such prroperty for testRunner class
  • Can u please reply back ....
    i have tried doing this too but i am getting CDATA error
    groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    holder = groovyUtils.getXmlHolder("Authenticate_User#Response" )
    authenticateUserResponse = holder.getNodeValue("//ns2:authenticateUserResponse")
    authenticateUser = groovyUtils.getXmlHolder(authenticateUserResponse)
    authenticateUserRespPayload = authenticateUser.getNodeValue("//ns2:authenticateUserRespPayload")
    authenticateUserRsp = groovyUtils.getXmlHolder(authenticateUserRespPayload)
    authToken= authenticateUserRsp.getNodeValue("//ns2:authToken")
    testRunner.testCase.testSuite.project.setPropertyValue("authToken", authToken)