Forum Discussion

richie's avatar
richie
Community Hero
6 years ago

Delete Project Level Properties With Specific Name After Execution

Hi,

 

Bit embaressed I can't fix this myself :(

 

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. :)

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

 

  • 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)}
  • nmrao's avatar
    nmrao
    Champion Level 3

    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)}
      • nmrao's avatar
        nmrao
        Champion Level 3
        It is important to function as desired, then efficiency. Will be a bonus if it comes with both.
  • Radford's avatar
    Radford
    Super Contributor

    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.