How Clear TestStep Values using TearDown Script
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,'')
}
}
}
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using Project level teardown script?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, check out the documentation for project, test suite and test case tear down scripts, it high lights the different properties provided in the various different teardown scripts.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way I would suggest in that case is to define the exclude property list in the script (better way) if less properties and clear the values conditionally. If there are too many properties to exclude, then you use include list and clear only those property values. Decide which one suites better for you.
say sudo code:
def excludeList = ['name1', 'name7']
if current property name not in the excludeList, then only clear.
This way, you do not have worry at all.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! After looking at both of your suggestions I was able to get the script to run as a project level Tear Down.
I did run the script "as is" to see how bad it would be if I removed all the properties... 🙂 It was pretty bad.
Luckily I made a backup as you both suggested.
I created an "if" statement to just target the apiKey, but I like the solution to use the exclude list and will probably try that instead.
You guys (@nmrao and @Radford) are awesome! Thank you for all the help!
