cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy Script to delete test cases that begin with value

Bensb93
New Contributor

Groovy Script to delete test cases that begin with value

Disclaimer - My knowledge of Groovy is very limited.

 

I basically require a groovy script within my test case to delete test steps that begin with 'Order'.

I have tried this below, but to no avail, but that's kind of what I want. No idea if the syntax is correct or not!

 

 

testSuite.removeTestStep.startswith(Order)

 

 

This script would ideally be at the bottom of the test case and delete all the test steps that begin with the word 'Order'

 

Any help would be greatly appreciated.

 

Many Thanks.

Ben

Tags (3)
5 REPLIES 5
ChrisAdams
Community Leader

Re: Groovy Script to delete test cases that begin with value

Hi,

 

Why would you want to use Groovy to delete test cases?  Can you just not delete from the 'tree' in the left pane?

Bensb93
New Contributor

Re: Groovy Script to delete test steps that begin with value

Hi Chris,

 

I have confused matters here and not used the correct terminology!

 

I wish to delete test steps, and not test cases, my apologies. I have updated the subject and initial post to reflect this.

 

But to expand on your question, I have a groovy script at the beginning of the test case, that imports XML files as "Test Cases", which could mean I end up with over a 100 test steps for this particular test case. What I wish for is the ability to delete all of these XML files, that all begin with the word "Order", rather than having to manually delete them and have it automated.

 

Hope that makes sense?

ZDGN
Contributor

Re: Groovy Script to delete test steps that begin with value

Hi @Bensb93,

 

Hope there is no misunderstanding between TestCase and TestSuite, but such a Groovy script should help you doing the job:

 

// Define the current TestCase
def currentTestCase = testRunner.testCase
// Loop for all steps inside the TestCase
for(step in currentTestCase.getTestStepList()) {
	// Define the step name
	def stepName = step.getLabel()
	// Condition of the test
	if (stepName.startsWith("Order")) {
		// Log
		log.warn "Step: ${stepName} will be removed !"
		// Remove the step
		currentTestCase.removeTestStep(step)
	}
} 

Tell us if it helps.

 

David.

Bensb93
New Contributor

Re: Groovy Script to delete test steps that begin with value

Hi David @ZDGN ,

 

Yes it does exactly what I requested, many thanks.

 

The only issue is that it deletes the test steps too fast, before they are able to pass through.

 

Is there a way to create a delay somehow? Whether its a defined time value that can be tweaked or a value that confirms they were sent? I effectively want to ensure the xml test steps to pass through before deleting them. 

 

Apologies, I am still fairly new to SOAP and groovy, its not my normal line of expertise.

ZDGN
Contributor

Re: Groovy Script to delete test steps that begin with value

Hi @Bensb93 

 


The only issue is that it deletes the test steps too fast, before they are able to pass through.


I thought this script would be executed as the last step of the TestCase.

 


Is there a way to create a delay somehow? Whether its a defined time value that can be tweaked or a value that confirms they were sent? I effectively want to ensure the xml test steps to pass through before deleting them. 


Of course some kind of delay defined by a property can be used.

 

You want to execute each steps of the TestCase before deleting some ?

So check my first sentence: this script should be at the end of the TestCase.

 

Could you try to explain how your TestCase is made and what is the expected behaviour ?

Must admit am a bit lost.

 

David.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors