Forum Discussion

James_Grace's avatar
James_Grace
Occasional Contributor
17 years ago

Dynamic (Unique) property variable in XML Request

Hi All,

The WebApp I'm testing requires a UniqueToken in the XML Request. Is there a way I can include a dynamic property variable in a XML Request?

I've tried dynamically entering a time variable in the -DsoapUI.properties=properties.txt file, but this appears to be read only at startup.

From what I can tell, Groovy script is an option before or after the Test Case is run. Not when it is run.

I don't need anything fancy, just a unique string. Something like the output from "time /t" would be fine.

Any suggestions to point me in the right direction would be much appreciated.

Thanks,
~Jim
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    try adding the following to your TestCases Setup script:

    context.randomId = Math.random()

    And then "use" the randomId variable in a request with

    ${randomId}

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • James_Grace's avatar
    James_Grace
    Occasional Contributor
    Thanks Ole,

    I can't seem to get this to work.

    I added the context.randomId = Math.random() to the Test Case setup

    and set the XML request like so, ${randomId}

    I've tried ${randomId} and ${#TestCase#randomId}. The property expansion is not happening. soapUI sends whatever I put in the UniqueToken holder.

    I tried added a def before the context.randomId = Math.random(), and creating the def other ways, but can't get the property expansion to work.

    I've also tried creating a UniqueToken groovy script containing the context.randomID function and using the result ni the XML request like so,
    ${#UniqueToken#randomId}

    What am I missing? I can't help but think it's something simple.
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    this solution will only work when you run the entire TestCase, not just an isolated Request inside it.. could that be the cause of your problem?

    regards!

    /Ole
    eviware.com
  • James_Grace's avatar
    James_Grace
    Occasional Contributor
    I've gotten the context.randomId = Math.random() to  return a value from a Groovy script Test Step, then Transfer the value (using a Property Transfer Test Step) to the final Test Step (Interactive Read ).

    I just haven't had any luck defining the Math.random() function in the Test Case Setup Script and having the Property Expansion work properly in the XML Request.

    It's probably a Scope or Syntax problem on my part. I'm still learning my way around soapUI. I'll keep poking around.

    Thanks much for the assistance & very nice work on soapUI. I've convinced my group to switch from soapScope and buy a few copies of soapUI. I expect to get lots time on it in the future.

    Have a good day!
    ~Jim
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    ok, sounds good! Contact me once you have the pro-licenses and we can set up a webex session to sort this out (if you want)..

    regards!

    /Ole
    eviware.com
  • James_Grace's avatar
    James_Grace
    Occasional Contributor
    Hi Ole,

    I got our SoapUI Pro licenses yesterday. I will put together a brief description of our Web App and some of the things I want to do and email it to you.

    Our Web App is not very complex and I think we can work out a lot of what I want to do with emails. If I cannot work things out after a few emails, we can go the Webex route.

    Thanks much,
    ~Jim G
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Jim,

    Thank you, we're proud to have you as a Pro-user :-)

    regards,

    /Ole
    eviware.com