Ask a Question

Creating a custom Delay teststep via a Groovy scripting step

SOLVED
hazel_chua
Contributor

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.

hazel_chua_0-1624453667054.png

hazel_chua_1-1624453741915.png

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.

 

 

8 REPLIES 8
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_0-1624496393860.png

 



Regards,
Rao.
nmrao
Champion Level 3

This way, one can disable / enable the test step "Delay" on demand without any issues.


Regards,
Rao.

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

hazel_chua_0-1624511562679.png

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

nmrao
Champion Level 3

Yes, i mean the same regarding disabling Delay step.


Regards,
Rao.

There is no visible property that I can set to change the test step from active to disabled or vice versa.  I can only seem to do it when I right click on the test step and then manually selecting either Enable or Disable.

 

Also, your concept didn't work.

 

hazel_chua_0-1624513248811.png

I am not seeing the delays.

I needed to change it to use ${#TestCase#TapTimeWindow} instead of what you used for the value of the delay

 

nmrao
Champion Level 3

@hazel_chua 

Not sure if you are using the way I showed you. May be just try what I showed in my screen shot.
Define custom property test case level and assign value.
For the delay step, assign the value that is shown.
The test case I created with 3 steps to demonstrate.
Step 1, groovy, just log statement to show the time.
Step 2, delay, the one that is needed
Step 3, same as Step1.
Let me know if the same doesn't work as is.

 


Mean while I see your example.

 

EDIT:

Attaching the test case XML in the link below. You can just import it in test suite to be try.

https://github.com/nmrao/sample-soapui-projects/blob/master/delayTestCase/soapuiTestCaseForDelay.xml



Regards,
Rao.
nmrao
Champion Level 3

@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

 

nmrao_0-1624520849687.png

 



Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: