Forum Discussion

morciani's avatar
morciani
Occasional Contributor
16 years ago

parsing text strings with Groovy script

Hello- I am new to Groovy script.  I have inserted the following property expansion / simple Groovy script into a soapUI Test Request:

...
${=context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()}
...

This works great, as my current Test Step name is inserted into my request like this:

...
01_R3_AK2_2772...

Next, I have an element that I want to populate with a substring found within this string, like this:

...
AK
...

I've tried various variations like below, all without any luck.

...
${=MID(context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel(),7,2)}
...

I am sure I am missing something.  Any help in pointing out how I can parse strings with Groovy script is appreciated...  Could someone point me to some examples?

1 Reply

  • morciani's avatar
    morciani
    Occasional Contributor
    I found my solution...  I needed to use the substring function like this:

    ${=context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel().substring(6,8)}

    Works great!  Easy!