Creating a custom Delay teststep via a Groovy scripting step
I managed to create a custom Delay test step via Groovy script but I can't seem to modify the step.
def stepName = "DelayTimeWindow"
def newPropertiesStep = testCase.getTestStepByName(stepName)
if (newPropertiesStep == null)
{
newPropertiesStep = testCase.addTestStep('delay', stepName)
}
I can't seem to modify the actual delay value (in milliseconds) nor am I able to disable the test step from the normal sequential execution of the test case after I create it via code.
I need to be able to set up a dynamic delay based on a value set by the 'main' script I have in the test case. The custom delay step is needed to be called by another (disabled) test step which is triggered by the 'main' test step calling it via the runTestStepByName() function.
I've tried to use Thread.sleep() but it seems to have messed up the whole test case when it woke up after that sleep(). I wasn't even getting proper logging info on the script log window at the bottom of the screen after that.
The test case contains multiple test steps that are all in the disabled state and only called via one main, active Groovy test step depending on multiple variables from an input spreadsheet and many of the test steps are being reused throughout the execution of the test case.
I tried the way you are showing, but it still works. Please find the test case link which can be imported into a test suite.
How to use:
- Import xml into test suite and run the Groovy Script test step.
What it does?
- This time, changing the value of CUSTOM_DELAY with in the groovy script and run the Delay step from within Groovy to see the delay is changed or not dynamically.
- Also Delay step is activated / deactivated and activated back to demonstrate. As you pointed you could not disable in you messages.
- In the below screen shot, you can notice the log time difference
- Initial value of property is 1s
- Test run #1 with 3sec delay
- Test run #2 with 10s delay
https://github.com/nmrao/sample-soapui-projects/blob/master/delayTestCase/dynamicDelayInGroovy.xml