How do you insert the same random variable into multiple soapui testcase requests?
Asked Answered
N

2

5

I may be going about this in the completely wrong way, but how do I pass a dynamic variable to a bunch of requests within the same testsuite in SoapUI?

My first test step is a Groovy script. I need to generate a random account name, and then use it in all my other requests. There are about 20 other requests. I initially thought I could just loop the testsuite, but it is not working.

This is my groovy script at the beginning:

Random random = new Random()

def randUserAccount = "testAccount" 

int max = 100000
randnum = random.nextInt(max+10000)

randUserAccount += randnum

log.info "     Creating account: $randUserAccount"

Then in each request step, I have things like this:

<ns:CreateAccountRequest>
    <accountID>${randUserAccount}</accountID>
...

or

<ns:PurchaseRequest>
    <accountID>${randUserAccount}</accountID>
...

The account is null when I actually send it, and of course that gives errors on the server side. How do I really get the variable to persist across all the requests in the testsuite?

Thanks in advance for any hints!

Notogaea answered 10/9, 2012 at 17:36 Comment(0)
A
9

You can use the context, I believe. You can definitely use it between requests in a test, but I also think it will work between tests in a suite.

context.setProperty("randUserAccount", randUserAccount)

Then use the syntax you specified in the actual requests.

Let me know if this doesn't work. You can also use 'properties' to do this, but it is a little more work.

Antelope answered 10/9, 2012 at 18:41 Comment(2)
Is this for Soap UI Pro or the free version? I tried that but when I try to access it, the request contains an empty value between tags. For example, <temp>${value}</temp> in the payload would have in the request <temp></temp>.Burkey
Since it is groovy, it should work just context.randUserAccount = randUserAccountCavill
S
-1

or you can create a variable in property then set the value through set property as mentioned above..

for every tag jus right click and check the your project varaible it will automatically insert the code..

Hope it help

Siderosis answered 19/12, 2013 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.