Forum Discussion

hazel_chua's avatar
hazel_chua
Contributor
3 years ago
Solved

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.

 

 

  • nmrao's avatar
    nmrao
    3 years ago

    hazel_chua 

    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

     

     

8 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    hazel_chua 

     

    Please set the value as dynamic evaluated property as shown below which is using test case level custom property:

    Changed custom property value between two tests and the same can be seen in the log timings

     

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      This way, one can disable / enable the test step "Delay" on demand without any issues.
    • hazel_chua's avatar
      hazel_chua
      Contributor

      What I mean by disabled is to set the test step to the disabled state so it looks like : 

      I'm just about to try out your method of setting the Delay property's value to a property expansion syntax

      • nmrao's avatar
        nmrao
        Champion Level 3
        Yes, i mean the same regarding disabling Delay step.