Forum Discussion

Kay's avatar
Kay
Occasional Contributor
6 months ago

How to remove (not clear) test case properties from SaveScript

Whenever I save my project, I want to delete all the testcase properties, otherwise I end up with many orphaned properties.  I've added this code into the save script hook

for ( testSuite in project.getTestSuiteList() ) {
      for ( testCase in testSuite.getTestCaseList() ) {
          if (testCase.getPropertyCount() > 0) {
              for( propertyName in testCase.propertyNames ){
                   testCase.setPropertyValue(propertyName, '');
              }
           }
       }
}

which clears all the properties.  However if there is a property which is no longer being used, that property remains.  Instead I want to delete them all.

I found this, but it is from 16 years ago and the link to docs no longer works.
Remove Properties of TestCase from Groovy. | SmartBear Community

It also talks about using the testRunner, but as far as I can tell, the testRunner isn't available in the saveScript, as no tests are being run...

  • Kay 

    Below script should help:

    project.testSuiteList.each { suit ->
    	suit.testCaseList.each { kase ->
    		kase.propertyNames.each {
    			kase.removeProperty(it)
    		}
    	}
    }

     

     

     

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    Kay 

    Below script should help:

    project.testSuiteList.each { suit ->
    	suit.testCaseList.each { kase ->
    		kase.propertyNames.each {
    			kase.removeProperty(it)
    		}
    	}
    }

     

     

     

     

    • Kay's avatar
      Kay
      Occasional Contributor

      Thanks!  That works perfectly!!

  • nmrao's avatar
    nmrao
    Champion Level 3

    Have a suggestion regarding the properties.

    There can be properties being created run time and some may need to be there always.

    In the script, we are trying to delete all of them. If we want to ignore certain properties, then we have to have little strategy so that what needs to be deleted and what needs to be there even after save script is run.

    Use small case for all the temporary property names. i.e., all these will be removed when project is saved.

    Use ALL capital letters name for the properties that are permanent and should not be touched by above save script.

    Here is the modified script to adhere the above strategy:

     

    project.testSuiteList.each { suit ->
        suit.testCaseList.each { kase ->
              kase.propertyNames.findAll { ! it.toUpperCase().equals(it) }.each { kase.removeProperty(it)}
        }
    }

     

  • minhng's avatar
    minhng
    Occasional Contributor

    Hi. I do not have any contribution to resolve this question but I have a similar concern relating to the same. I see that the search results from a JDBC-test step are stored in the project. It makes the file size turns out to be huge and impossible to push into GitHub - where the file size limit is 50MB.

    My question is how to prevent test runs from storing JDBC response in the file and how to remove those in existing files.

    Thanks in advance.