Forum Discussion

smadji's avatar
smadji
Contributor
10 years ago

[Res]how to add property into header

I have created a property that is dynamically updated with a token (via groovy script)
Now I need to bring the content of the property into my header.
I found a page in the documentation that says this is possible
http://www.soapui.org/SOAP-and-WSDL/add ... tp-headers
and a page showing me how to do this:
http://www.soapui.org/Scripting-Propert ... nsion.html

But when I tried to construct the actual text from the instructions - I cant get it to work.
Here is what the documentation has me follow:
${[scope]propertyName[#xpath-expression]}

The scope is going to be my suite case (at the suite level is where I created my property)
the property name is token
I dont think there is an xpath for the property

can someone tell me what I should put in the header to get this to work?
Thanks
Smadar

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can set the header since you have the value, you can save it on testSuite level and try this code,

    import com.eviware.soapui.support.types.StringToStringMap

    def request = context.testCase.testSteps["Test Request"].testRequest
    def headers = request.getRequestHeaders()

    headers["TestHeader"] = //add your property value here

    request.setRequestHeaders(new StringToStringMap(headers))


    Thanks,
    Jeshtha
  • elysialock's avatar
    elysialock
    Occasional Contributor
    It should be pretty straightforward; I'm wondering if you've formatted your property expansion correctly.

    Say I have a TestSuite level property named tokenA that I want to use as the token. So my header setup would look like this, with the property expansion formatted like ${#TestSuite#tokenA}:


    I think that should work.

    -E
  • Thank you elysialock! You have made it work.
    I love you! LOL
  • elysialock's avatar
    elysialock
    Occasional Contributor
    I'm glad I could help. I remember the documentation being a bit confusing when I was trying to learn how property transfers work. Happy testing!

    -E