Forum Discussion

maxrussell's avatar
maxrussell
Contributor
16 years ago

Inserting a random ID into a request parameter

I have a request that has tags like this:

                        <tem:Type>ID</tem:Type>
                        <tem:Value>4111138624</tem:Value>


What I'd like to do is to pick a random value out of a list or array of ID values.

I've create a really simple little Groovy script like this:

idnos = [4111138624, 4111155065, 4111152198]
rand = new Random();
randnhs = idnos[(rand.nextInt(3))];


How do I actually get the VALUE tag to use the randomly returned value?

ta

(I've had a look through the documentation, but can't really find what I'm looking for.)

2 Replies

  • It's not perfect, but this is one way:


        <tem:Type>ID</tem:Type>
        <tem:Value>${#TestCase#thingValue}</tem:Value>


    Then in the Ruby bit:


        testRunner.testCase.setPropertyValue('thingValue', idnos[(rand.nextInt(3))].toString());


    [edit: http://www.soapui.org/userguide/properties.html ]
    You can probably be a lot neater than this, though.
  • EDIT - (found the part in the reference dealing with this... "is #TestCase a specific convention, or arbitrary?")

    That now works, ta. What I find is that it always selects the same ID from the array now.