cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Project Level Properties With Specific Name After Execution

SOLVED
Highlighted
Community Hero

Delete Project Level Properties With Specific Name After Execution

Hi,

 

Bit embaressed I can't fix this myself Smiley Sad

 

I have some project level properties I create after running a setup testsuite to grab some GUIDS out of the database for later use in the project and I'd like to delete these project level properties after each execution run. 

 

I have a number of project level properties and I only want to delete ones containing a certain string in the property name, so I was thinking add a script to the project teardown.

 

I almost found exactly what I needed via this link

 

In the linked page @HimanshuTayal 's code reads as follows (which gets added to the testCase teardown script):

 

 

def targetTestCase = testRunner.testCase;
def propList = targetTestCase.getPropertyNames()
propList.each{
	if(it.contains("ScheduleID")){
		targetTestCase.removeProperty(it);
	}
	else{
		//Do nothing
	}
}

 

HOWEVER - the above is to delete testcase level properties rather than project level properties - so I altered it to the following (added it to the Project teardown script) thinking this would work

 

def targetTestCase = testRunner.testCase.testSuite.project;
def propList = targetTestCase.getPropertyNames()
propList.each{
	if(it.contains("ScheduleID")){
		targetTestCase.removeProperty(it);
	}
	else{
		//Do nothing
	}
}

But I got the following error response

Tue Jun 18 10:57:20 BST 2019: ERROR: com.eviware.soapui.support.scripting.ScriptException: Error in TearDown Script of Eehatevs

Can anyone see what I'm doing wrong? well - I'm sure everyone can see what I'm doing wrong - but  I cant. Smiley Happy

I checked around and to navigate to the project level - (in the testRunner line) and that appears how to drill to the project level? (e.g. testRunner.testCase.testSuite.project)??

 

Cheers!

 

richie

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Delete Project Level Properties With Specific Name After Execution

@richie 

 

Hope below helps for the same.

 

//Add the property (exact) names to be removed in below statement, comma separated if more than one
def listToRemove = ['ScheduleID']
listToRemove.findAll { it in project.propertyNames }.each { project.removeProperty(it)}


Regards,
Rao.
4 REPLIES 4
Community Hero

Re: Delete Project Level Properties With Specific Name After Execution

@richie 

 

Hope below helps for the same.

 

//Add the property (exact) names to be removed in below statement, comma separated if more than one
def listToRemove = ['ScheduleID']
listToRemove.findAll { it in project.propertyNames }.each { project.removeProperty(it)}


Regards,
Rao.
Community Leader

Re: Delete Project Level Properties With Specific Name After Execution

If you know the property name you should be able to use this code (Note: This is run from a test case teardown script, you need to tweak how you get the project object), just substitute the name of your project property:

 

def project = testCase.getProject()

project.removeProperty('TestProp')

The project object is the class WsdlProject, the removeProperty method is specified by the inherited class AbstractTestPropertyHolderWsdlModelItem.

Community Hero

Re: Delete Project Level Properties With Specific Name After Execution

hahaha! wow! both options look efficient!

 

Cheers @nmrao & @Radford 

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: Delete Project Level Properties With Specific Name After Execution

It is important to function as desired, then efficiency. Will be a bonus if it comes with both.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors