Forum Discussion

nullop's avatar
nullop
Occasional Contributor
13 years ago

Making sequence numbers

I have not found out how to do this functionality:

myNum starts as 1.
<myTag>
<option>${DataGen#myNum}</option> // should put 1 in here
<option>${DataGen#myNum }</option> // should put 2 in here
<option>${DataGen#myNum }</option> // should put 3 in here
</myTag>

If I run the test case again it should start at 4. I need a string before the number… Stepping through an int is not as flexible as what I need. Making 3 separate ints is too cumbersome. I may need 512 ints that follow this pattern.

Any idea how to approach this?

I have been looking into XmlParser & XmlSlurper... I do not know if that is the right path yet.

1 Reply

  • SiKing's avatar
    SiKing
    Community Expert

    1. Create a testcase property called myNum (looks like you already have this), and set it to 0.

    2. Your test case should have:
      <myTag>
      <option>${=${#TestCase#myNum} + 1}</option> // should put 1 in here
      <option>${=${#TestCase#myNum} + 2}</option> // should put 2 in here
      <option>${=${#TestCase#myNum} + 3}</option> // should put 3 in here
      </myTag>

    3. Create a testcase Tear Down script:

      def lastOption = context.expand( '${#ResponseAsXml//option[last()]}' )
      testCase.setpropertyValue("myNum", lastOption)

    4. Disclaimer: this may need some fine tuning, but hopefully you get the idea.