Forum Discussion

nmrao's avatar
nmrao
Champion Level 3
5 years ago
Solved

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/154115

 

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.

 

 

  • 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

     

     

     

18 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    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)
    • JoostDG's avatar
      JoostDG
      Frequent Contributor

      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.

      • nmrao's avatar
        nmrao
        Champion Level 3

        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 .

  • ArthurM's avatar
    ArthurM
    Occasional Contributor

    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 ?

    • nmrao's avatar
      nmrao
      Champion Level 3

      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.

      • nmrao's avatar
        nmrao
        Champion Level 3

        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.

    • _ivanovich_'s avatar
      _ivanovich_
      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

  • Great work nmrao , this will surely help all of us who are using composite project while merging. :)

     

    Kudos to you !!!!

  • 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] );
    }