cancel
Showing results for 
Search instead for 
Did you mean: 

Solution Script to Cleanup of Custom property values in the project

SOLVED
Highlighted
Community Hero

Solution Script to Cleanup of Custom property values in the project

It is noticed that many were looking for a feature where users like to clean the custom property values. This eases to push the actual changes to repository (instead of just property values changes).

 

Here is the context and feature request that was submitted long time ago and many were seeking this feature.

 

https://community.smartbear.com/t5/ReadyAPI-Feature-Requests/Saving-without-property-values/idi-p/15...

 

Here I came up with a script which does exactly users are asking for.

 

- In order to make the script flexible and dynamic, user need to add a project level property, say CLEAN_PROPERTIES and "false" as default value.

 

- Though users like to clean property values, some might still wish to keep value for certain properties. To accomodate, users can add the property names which they don't want to clean up. Allows properties at test case, suite, and project levels. You don't have to do anything if you want to clean all properties.

 

- The script has to be copied in the "Save Script" tab at the project level (double click project to see the same)

 

- You don't have to run this script manually, this will  automatically get triggered when project is saved on a condition that CLEANUP_PROPERTIES value is set true. Once it cleans the properties, the value is set to false to allow users not show the (repository) differences. This condition helps not to lose the property values while work in progress and project is saved. Once user changes to the project are complete and about to check-in the changes in to repositories, set the value to true and save. Now the project is ready the way users wanted.

 

Here goes the script:

 

/**
* Project level's Save Script
* Cleans up all the custom properties 
* If CLEAN_PROPERTIES value of project property is set to true
* And save the project
*
*/

def ignoreTestCaseProperties = [ ] 
def ignoreTestSuiteProperties = [ ] 
def ignoreProjectProperties = ['CLEAN_PROPERTIES'] 
def cleanProperties = { model, list -> model.properties.keySet().findAll{ !(it in list) } each { tProp -> model.setPropertyValue(tProp,'') } }
if ('true' == project.getPropertyValue('CLEAN_PROPERTIES')) {
	project.testSuiteList.each { tSuite -> 
		cleanProperties(tSuite, ignoreTestSuiteProperties)		
		tSuite.testCaseList.each { tCase -> cleanProperties(tCase, ignoreTestCaseProperties) }	
	} 
	cleanProperties(project, ignoreProjectProperties)	
	project.setPropertyValue('CLEAN_PROPERTIES', 'false') 
}

Hope this is useful.

 

 



Regards,
Rao.
18 REPLIES 18
Highlighted
Frequent Contributor

@ArthurM 

Hi,

i'm interested to see your solution for cleaning dynamic and static properties.

the link seems not to refer to your solution or i made a mistake.

Can you send again the link please.

nmrao's solution looks good too.

i want to try both solutions.

For now i just have a regular groovy script with a list of properties to clean

 

Thank you

Highlighted
Frequent Contributor

Thank you so much - - > Arthur.
Highlighted
Community Manager

Awesome stuff, thank you @nmrao . A lot of people will benefit from this.


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Frequent Contributor

Hi,

i found nmrao's solution fine.

Arthur's solution is nice too.

For now i prefer to use this simple solution in 'setup script' for example to clear testcase properties:

context.testCase.properties.each {
context.testCase.properties[it.key].value = ''
}

But Arthur's solution looks nice because we can delete all properties ending with a certain suffix.

I need to work on these two solutions to avoid the repetition of my two lines in each testcase for example.

But when we execute several times the same test, we overwrite properties right?

It's not clearing but changes the same properties each time we execute.

Thank you

 

 

 

View solution in original post

Highlighted
Frequent Contributor

please give my kudo to Arthur.

thank you

Highlighted
Community Hero

Reiterating that the solution is provided in the context of pushing the changes to repository for actual changes to the project rather than just property value changes because of test run.

As mentioned in one the replies in the above, user can remove properties altogether or just remove values as per the need.


Regards,
Rao.
Highlighted
New Contributor

int proptyCounts = testRunner.testCase.propertyCount
String [] tcexe_ToRemove = new String[proptyCounts]
for(int i=0;i<proptyCounts;i++)
{
    propertyName = testRunner.testCase.propertyNames[i]
    tcexe_ToRemove [i]=propertyName.toString().trim()
}
for(int j=0;j<tcexe_ToRemove.size();j++)
{
     testRunner.getTestCase().removeProperty(tcexe_ToRemove[j] );
}

Highlighted
Frequent Contributor

Thanks a lot

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors