Forum Discussion

Fergus's avatar
Fergus
New Contributor
16 years ago

Groovy to add additional HTTP Headers from property file

Hi,

I'm using soapUI 2.5 Beta1 and it's awesome.

I've created a TestSuite with TestCases each comprising a number of individual SOAP requests.

Due to the strict SSL security setup in our environment for each SOAP request message to be successful I have to manually add an additional HTTP header named MYSAPSSO2 with value = to an encrypted ticket string ( e.g. YycXopljagdalfgjadlj).
This ticket value actually corresponds to an individual system user's logon ticket but has to be added as an additional HTTP header.

To get this right I simply use the additional HTTP headers button and copy and paste MYSAPSSO2 and the ticket string into the corresponding fields as shown in the userguide:
http://www.soapui.org/userguide/request ... TP_Headers

This works great! ... and saved a lot of earlier pain and struggle   :)
Thanks!

My problem is that I've moved into territory where I've got over 40 individual SOAP requests (in many TestCases) in just one TestSuite (and I'm planning on building a few more TestSuites..), so manually adding the additional HTTP headers to each and every request isn't an option anymore. It's proving to be really time consuming and not so flexible.

I'd also like to use a variation of values for the additional MYSAPSSO2 header in order to mimic a variation of different system users performing individual TestCases.

The answer seems pretty simple to me but I'm struggling on the Groovy side. The high-level steps I'm taking are as follows:

1. Create a property file with a variation of ticket values (for the additional MYSAPSSO2 HTTP header).

2. Write some groovy that (for each execution iteration of the testcase) will pull a new ticket value into a property named MYSAPSSO2.

3. Write some groovy that inserts the property MYSAPSSO2 and it's updated value as additional HTTP header to each of the requests in the TestCase per TestCase iteration.

I have got steps 1 and 2 out of the way and am effectively able to update the value of MYSAPSSO2 in the properties step with a new value upon each iteration of the TestCase 

I am struggling to write the groovy for step 3 

Can you assist with a simple piece of groovy that I can place after the Properties step that would pull the updated MYSAPSSO2 property value and insert it into an additional HTTP header named MYSAPSSO2 (in each of the SOAP requests that follow the groovy step) thus enabling all the SOAP requests in the TestCase to receive the newly updated HTTP header?

Any assistance would be greatly appreciated - and also if you think my approach is wrong and can suggest a better approach this would also be really appreciated.

Kind Regards,
Fergus

2 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Fergus,

    Maybe you could just add the desired header to all your requests and set its value using property-expansion, ie

    ${#TestCase#MYSAPSSO2}

    if you have set the property on the TestCase level.. (where are you storing it?)

    regards,

    /Ole
    eviware.com
  • Fergus's avatar
    Fergus
    New Contributor
    Hi Ole,

    Thank you for such a timely response.

    This works great and is a more straight forward approach than that which I was attempting.

    I am now setting the property at the TestCase level.

    Thanks again! 
    Kind Regards,
    Fergus