Forum Discussion

kahmaui808's avatar
kahmaui808
Occasional Contributor
8 years ago
Solved

How Clear TestStep Values using TearDown Script

I have two projects. Project 1 is encrypted and has all the values for Project 2.

 

Project 2 runs and retrieves the values from Project 1, executes the tests and then I need Project 2 to get rid of all the values.

 

This is what I found in another post to remove the properties at the project level. I tried this and it works.

 

project.getPropertyNames().each{ propName ->
     log.info "remove prop: $propName"
     // set it's value as an empty string
     project.setPropertyValue(propName,'')
}

 

I modified the above code to target the four testSuites that have testCases that need to be cleared and came up with this. This works too.

 


for (testCase in Integrated.getTestCaseList()){
     testCase.getPropertyNames().each{ propName ->
          log.info "remove prop: $propName"
          // set it's value as an empty string
          testCase.setPropertyValue(propName,'')
     }
}

 

But I noticed I need to clear values at the testStep level. I tried this, but it doesn't work.

 

for (testCase in BvtSingle.getTestCaseList()){
     testCase.getPropertyNames().each{ propName ->
          log.info "remove prop: $propName"
          // set it's value as an empty string
          testCase.setPropertyValue(propName,'')
               for (testStep in testCase.getTestStepList()){
                    testStep.getPropertyNames().each{ propTSName ->
                         log.info "remove prop: $propTSName"
                         // set it's value as an empty string
                         testStep.setPropertyValue(propTSName,'')
                    }
              }
         }
}

  • I'm not sure if this is any help, but...

     

    [Edit: Amended script after comments below]

     

    I took a look at this and came up with the following project teardown script:

     

    project.getTestSuites().each {testSuiteName, testSuite ->
    	log.info('Test Suite: ' + testSuiteName)
    	testSuite.getTestCases().each{testCaseName, testCase ->
    		log.info('Test Case: ' + testCaseName)
    		testCase.getTestSteps().each{testStepName, testStep  ->
    			log.info('Test Step: ' + testStepName)
    			if(testStep in com.eviware.soapui.model.TestPropertyHolder){
    				testStep.getProperties().each{propName, prop ->
    					if(!prop.isReadOnly()){
    						// You may want to only remove properties based on property name here...
    						log.info('Initial: ' + propName + ' = ' + prop.getValue() )
    						prop.setValue('')
    						log.info('Removal: ' + propName + ' = ' + prop.getValue() )
    					}
    				}
    			}
    		}
    	}
    }pre>

     

    Interestingly I also saw that while some were removed with some properties not marked as read only they would not be removed, no error was raised either.

     

    As a side note, this script is quite brutal in the way it attempts to remove all properties including all the ones that configure the test step, did you really want to do this or was it specific properties you wanted to remove?

7 Replies

  • Radford's avatar
    Radford
    Super Contributor

    I'm not sure if this is any help, but...

     

    [Edit: Amended script after comments below]

     

    I took a look at this and came up with the following project teardown script:

     

    project.getTestSuites().each {testSuiteName, testSuite ->
    	log.info('Test Suite: ' + testSuiteName)
    	testSuite.getTestCases().each{testCaseName, testCase ->
    		log.info('Test Case: ' + testCaseName)
    		testCase.getTestSteps().each{testStepName, testStep  ->
    			log.info('Test Step: ' + testStepName)
    			if(testStep in com.eviware.soapui.model.TestPropertyHolder){
    				testStep.getProperties().each{propName, prop ->
    					if(!prop.isReadOnly()){
    						// You may want to only remove properties based on property name here...
    						log.info('Initial: ' + propName + ' = ' + prop.getValue() )
    						prop.setValue('')
    						log.info('Removal: ' + propName + ' = ' + prop.getValue() )
    					}
    				}
    			}
    		}
    	}
    }pre>

     

    Interestingly I also saw that while some were removed with some properties not marked as read only they would not be removed, no error was raised either.

     

    As a side note, this script is quite brutal in the way it attempts to remove all properties including all the ones that configure the test step, did you really want to do this or was it specific properties you wanted to remove?

    • kahmaui808's avatar
      kahmaui808
      Occasional Contributor

      Thanks, but it didn't work. testRunner is not available in the TearDown. Is there a way to make testRunner available in the TearDown or can Runner be used?

       

      I'm trying to remove all the user data and apiKey information from the project after successful test execution. If someone were to pull down the unencrypted project, they should not see any user data or apiKeys. I don't want to encrypt the project because I want to keep the composite project structure (encrypting forces a single project structure).

       

       

      • Radford's avatar
        Radford
        Super Contributor

        After reading the comments I have amended my script to run as a project teardown script.

         

        IMPORTANT: Before testing this script I recommend that you make sure you have a back up, if you start deleting properties you didn't mean to you may end up in a real mess.