Forum Discussion

Daimiel's avatar
Daimiel
New Contributor
15 years ago

Property Transfer: HTTP response header

Hi all,

I have been trying to use the header of a http response of a test step A as a parameter for the next test stepB.

I tried to update a request parameter of A by treating the response with a groovy script, and also by means of a property transfer...

Somebody to bring light to me?

Thanks in advance
  • Not sure if this is what you're looking for:

    //Takes one of the elements of the response Header
    def value = testRunner.testCase.testSteps["Request"].testRequest.response.responseHeaders["Set-Cookie"]

    //Read this value into a parameter
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    groovyUtils.setPropertyValue("Properties", "LTPA", value.toString())

    You can then use this parameter in later test steps.
  • It worked for me, too.  But I want to make sure I understand how this is working.  I had to change the string "Properties" to be the string name of the request in which I wanted to set the property.  So are the first two parameters to the setPropertyValue() method actually requestName, then propertyName?

    Also, what is "LTPA"?  It works, but I don't know why.  I was trying to set the Cookie HTTP Request Header parameter, and it worked, but I don't understand how I was supposed to know "LTPA" would do that.

    Actually, I had expected that by checking the box for "Maintain HTTP Session" that none of this would be necessary.  But checking that box did not cause the first response's 'Set-Cookie' value to be used in the second request's 'Cookie' attribute in the HTTP request header.  Is that an incorrect assumption?  if so, what does that checkbox do?

    (I'm using an evaluation verions of SOAPUI Pro 3.5 Build dist-88-2010-03-02)

    Thanks.

    def cookie_vals = testRunner.testCase.getTestStepByName("Request1").httpRequest.response.responseHeaders["Set-Cookie"]
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    groovyUtils.setPropertyValue("Request2", "LTPA", cookie_vals.toString())
  • Sorry, in retrospect I should have probably been much clearer in my reply.

    Yes, you're spot in with your belief of what the two parameters are.
    In the example below I'm storing the read in value to a Property rather than using it directly in a Request.  I have my Properties Test Step named "Properties" and one of the Properties within this is named "LTPA".  It is to this so named property that the read in value will be stored.
  • bennythedroid's avatar
    bennythedroid
    Occasional Contributor
    First off, thank you.

    I was able to transfer and id from the POST Header to a GET in the test case. The only remaining problem is that it inserts the id into the GET with [] around it. So when I try to actually run the GET, it fails because its looking for [idvalue] instead of just "idvalue".
    • bhajanmehta's avatar
      bhajanmehta
      Visitor

      bennythedroid : As you are getting value with square bracket [], it means that it is a array of string, can you please have a try with using index, like:

       

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
      groovyUtils.setPropertyValue("Request2", "LTPA", cookie_vals.[0])

      • nadamat's avatar
        nadamat
        New Contributor

        bhajanmehta 
        I'm also facing a similar issue.


        def value = testRunner.testCase.testSteps["GetToken"].testRequest.response.responseHeaders["Authorization"]
        def tc = testRunner.testCase.testSuite.getTestCaseByName("JTY")
        tc.setPropertyValue("_csrf", "$value")

         

        I'm able to get the value to the required property but in [ ]. 
        Can someone please help me in how to get rid of those square brackets from value.

    • nmrao's avatar
      nmrao
      Champion Level 3
      Please avoid duplicate postings. And there is no point in doing so.