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?