Forum Discussion

atts's avatar
atts
Occasional Contributor
16 years ago

howto property transfer between two HTTP requests

Folks,

I have a test-case with multiple test steps.  The test case has two HTTP Test Requests.
Does anyone know how to extract parameters from the response of the first HTTP request
and transfer to the second?   Basically the first HTTP requests responds with a session-id (along with other parameters) which needs to be used for the second request.

I've tried using the "Property Transfer" method, but this transfers the entire response to the
second HTTP request.  Anyone know how to extract specific data from the response?

thanks
atts.
  • atts's avatar
    atts
    Occasional Contributor
    Ok, I can't believe no one else has not needed this feature?  Do I have to use a groovy script to extract and transfer the returned data?
  • atts's avatar
    atts
    Occasional Contributor
    So here's my solution in case someone else needs to do something similar.
    Not saying this is the best way - I hope there's a much simpler way, if so please feel free to update this post ;-)


    My first HTTP request returns the following;


      746223053
     
      0
      AAABIy4kyFzg69MSRQHUa4Mzy9vsxkzTKj29HCbg3AMpYj8QOvhuIqdMncTIlvQ8GC2Y07JaTFfdxq4oE9rs5A==


    I want to extract the token string "AAA...." and feed it into subsequent HTTP/SOAP requests.

    My test steps are ordered as follows;

    Properties etc
    ...
    SOAP Request
    HTTP Request          <---  Returns a token
    Groovy Script          <---  Extract the token string, and set a Property value.
    Property Transfer    <---- Transfer the property to next HTTP request.
    HTTP Request          <---- Uses token from previous request.
    SOAP Requsts
    ...



    The Groovy script used is as follows;

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def httpResponse = context.testCase.testSteps["signOnByMACAddress"].testRequest.response.responseContent
    def REGEX = /"token":"(.*)"/
    def token = (httpResponse =~ REGEX)
    groovyUtils.setPropertyValue("Properties", "Token", token[0][1])



    cheers;
  • Hi,

    Inside SoapUI installation there is a folder named Tutorials which includes some sample projects. TestCase called "Simple Login and Logout w. Properties Steps" does exactly what you need, if I understand you well.
    Although you found solution yourself, you might want to check it out.
    Regards,

    /Dragica
    eviware.com
  • atts's avatar
    atts
    Occasional Contributor
    Dragica,

    All the test steps in the example(s) use SOAP requests.  The problem I had was when inserting a
    property transfer step.  May be I was trying to use it incorrectly?

    Test Steps:

    HTTP_Request_1
    Property Transfer
    HTTP_Request_2

    After inserting the Property Transfer step, I set the source as the first HTTP_Request_1, the Property to Response.  Then set the Target as HTTP_Request_2, Property to an arg value.

    nothing gets transfered, selecting the "ns:" button reports "Property Source and Target Source is not a request" ...  ?  I think this behaviour is a feature that I don't understand.

    what do you think?
  • atts's avatar
    atts
    Occasional Contributor
    Applogies for the delayed response,  unfortunately the suggestion to manually specify a namespace
    did not work, I get the following error when I run the selected Property Transfer;

    [error: Unexpected element: CDATA]

    I have to confess, I have discovered an error, the details posted below suggests the data comes back
    in XML format, it's actually JSON - I had been looking at the XML tab rather than JSON tab.

    {
      "result": null,
      "requestId": 1707347729,
      "resultCode": "0",
      "token": "AAABI1b1xbnXMkaY6c2UH9w0B52hm6p2TElOII485z!iF3yRVq!DXIjF74!rNEIXvOgZZZNCoGM="
    }

    Does this make any difference?
  • Hi!

    yes.. you need to set the source property to "ResponseAsXml", not "Response".. does that help?

    regards!

    /Ole
    eviware.com
  • atts's avatar
    atts
    Occasional Contributor
    I've tried "ResponseAsXML" too, that returned :-

    [null]


    this is what I'm using;

    declare namespace ns1='http://192.168.1.213:8180/path/to/Service;
    //ns1:token


    Is the above syntax correct?  I assume the namespace should be exactly the same URL
    as that used to make the HTTP request?
  • Hello all,
    I have similar issue and i've scratched my head to find a solution. Here is the scenario :

    i have REST request which returns json content in my test case, and i need to make some assertions on the result. As i usually do in a SOAP response, i wrote some xpath assertions like the following :

    declare namespace ns="http://localhost/mycontext/user"
    //ns:Response/ns:userInfo/ns:address/ns:address


    but the problem is that the namespace of the xml generated by "ResponseAsXML" depends on the url endpoint of the service i call. So if switch to another endpoint, all of the assertions on my test fail because all of the xpath points to nothing.

    Do you guys have ideas how to work around this ? Is there a way to get rid of the namespace in the "ResponseAsXML" of a json response ?

    Thanks in advance,

    HR