Forum Discussion

M_BEAR's avatar
M_BEAR
Senior Member
7 years ago

Script Libary - making it work when running from another step (eg. while looping)?

Can anyone help with a little issue when using a script Library (Like described here: https://community.smartbear.com/t5/SoapUI-Pro/How-to-write-a-reusable-script-Library/td-p/29499)

I use Ready Api 2.2, but my work should be possible to run at older versions and non pro versions of soapui.


I have a script that fetches some data and does some string manipulation in a property step just after my script. My script already uses testRunner and context - it works as a charm when just running a single testcase, BUT when I add a loop in my testcase, the context from the loop is passed to my script and suddenly it does not work.

I call my step from the loop teststep with:

 

testRunner.testCase.getTestStepByName("ContainerHelper 1").run(testRunner, context)

 

In my script this time named "ContainerHelper 1" I use the context to get the current step and the step afterwards.

 

def thisTestStepLocal = context.getCurrentStep()
def nextStepLocal = testRunner.testCase.getTestStepAt(currentStepIndLocal + 1)

 

However - now the context is the one from the loop-step, instead of the context from "ContainerHelper 1". For fun I just tried to add a property-step after my loop, and as expected it now uses this step for output instead of the property-step just after "ContainerHelper 1".

 

Can anyone help my: eg. by another way of getting the the current step and the step afterwards in my "ContainerHelper 1" when the script is run from another step,  eg. without using context or testRunner. Or another solution. I really like the idea of using a shared code Library and would like to keep it.

:-)