Forum Discussion

smadji's avatar
smadji
Contributor
10 years ago

generalizing an expression - beginner user needs help :)

I have a groovy script that I use as an assertion The script is working fine with a direct expression generated by the 'get data' tool I am trying to cut off the part that makes the expression look...
  • Armageddonsoft's avatar
    Armageddonsoft
    10 years ago

    OK, got it. Well, getting test step names i pretty simple, however you will need to supply the 0-based index of where the desired step is meaning that if you want to generalize you have to put that particular step at the same index everywhere (btw, test step name is the same as the request name). Here goes:

    def testStepName = context.testCase.getTestStepAt(n).getName()

     

    where n is the 0-based index. Now you can simply use testStepName here:

    def request_total = context.expand('${' + testStepName + '#response#$[n].totalCount}')

     

    Notice that since testStepName is a variable you have to concat the strings, hence the ' and the + surrounding it.