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.
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Occasional Contributor

Re: Solution Script to Cleanup of Custom property values in the project

Highlighted
Frequent Contributor

Re: Solution Script to Cleanup of Custom property values in the project

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

18 REPLIES 18
Highlighted
Community Hero

Re: Solution Script to Cleanup of Custom properties in the project

By the way, I prefer not even keep the property names. If you want the same? Then just do small change below.

In that case, just replace

model.setPropertyValue(tProp,'')


with

model.removeProperty(tProp)


Regards,
Rao.
Highlighted
Contributor

Re: Solution Script to Cleanup of Custom properties in the project

Thanks a lot @nmrao  !  I know @ArthurM  also gave hints for a similar solution, but nice to see it in a pre-packed handy (working)  script. 

FYI: For everyone looking for the project save script tab in ReadyAPI 3.1 (double-clicking the project didn't do the trick for me): 

  1. Right-click your project and select Project Settings.

  2. Switch to the Save Script tab.

Highlighted
Community Hero

Re: Solution Script to Cleanup of Custom properties in the project

@JoostDG ,


Thank you for correcting the way to locate Save Script.

Hoping that this would eases/minimizes the work for people and would be happy if many members uses it .



Regards,
Rao.
Highlighted
Community Hero

Re: Solution Script to Cleanup of Custom properties in the project

Hey!

 

this is great - the way I've been doing this before is to have a couple of separate scripts I created to get this sorted and even then it was clunky.

 

Such a way more elegant solution to the whole thing - kudos to @nmrao - I'm definitely gonna be using this in future - so thanks a lot!

 

Cheers,

 

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 Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Solution Script to Cleanup of Custom property values in the project

@nmrao  great job, very accurate and concise scirpt.

 

One thing I have done differently is instead of storing properties to be excluded in lists inside the script, I was using a naming convention - if variable name ends with '*', I treat it as dynamic and clean the value, otherwise treat it as static and leave. I think in a big project, where you have dozens of properties on all levels, might be difficult to keep track of all properties, and using naming convention to differ between dynamic and static properties might be easier. Here is my solution.

 

I am not familiar with 'Save script', looks like a new feature in ReadyAPI. Is it a script that runs as you save the project ?

Community Hero

Re: Solution Script to Cleanup of Custom property values in the project

@ArthurM 

Thank you.

 

Your idea, using some notation like regex, is nice.

However, like I mentioned(in the 2nd message), if the properties are dynamic, then there is no point even keeping the names in the project which will reduce some bytes of project file size.

 

Usually even keep the static properties in a separate file, this will allows to have data such as urls, db details of different environments and a small script in load script (project level) will load the properties when a project is opened. This allows to load different static values withouteven opening the project, and pass different propery file at command line.



Regards,
Rao.
Highlighted
Community Hero

Re: Solution Script to Cleanup of Custom property values in the project

And by the way, the "Save Script" is not something new. That is basic feature even available for years in SoapUI Open Souce as well.

 

So the above script works in SoapUI OS too.



Regards,
Rao.
Highlighted
Occasional Contributor

Re: Solution Script to Cleanup of Custom property values in the project

@nmrao  good ideas, will give it a try next time I work with SoapUI again.

Highlighted
Community Leader

Re: Solution Script to Cleanup of Custom property values in the project

Great work @nmrao , this will surely help all of us who are using composite project while merging. 🙂

 

Kudos to you !!!!


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
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

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Filtering data retrieved from a DataSource

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors