Forum Discussion
- Akuratere8 years agoNew Contributor
Hi Rao,
Sure, here's the script that erases values of properties in the test case:stopp = propTestStep.getPropertyValue("Stop")
if (stopp == "T"){
def p = myTestCase.testSteps["Properties"]
String[] properties = new String[p.getPropertyCount()]
properties = p.getPropertyNames()
for (int i=0; i<properties.size();i++){
p.setPropertyValue(properties[i], "")
}
propTestStep.setPropertyValue("Count", "1")
propTestStep.setPropertyValue("keyValue", "1")
}
- nmrao8 years ago
Champion Level 1
Which line of the script causing the issue? Stack trace from error log, please?
Seems ok, can be optimized though. - Radford8 years agoSuper Contributor
Are you sure of which proprties are casing the Cast errors? The reason I ask is that you mention that the two properties:
- Count
- keyValue
Were used for iterations, but the cast errors are when attempting to convert a string to Boolean. I also notice that you have a property which you are checking if equal to "T" (which I assume means "True"). Perhaps rather than blanking all properties, maybe some should be set to true or false (or "T"/"F") depending on your use case.
- nmrao8 years ago
Champion Level 1
That part of the code i.e., if (stopp == "T") is ok. Because, when property value is read, though value is true or false, it is a string only.
- nmrao8 years ago
Champion Level 1
May be see if the below one helps.
propTestStep = context.testCase.testSteps['Properties'] //Clear all the property values if Stop property value is T and do not clear its value def result = ("T" != propTestStep.properties['Stop']?.value) ?: propTestStep.propertyNames.findAll { it != 'Stop'}.collect{ propTestStep.setPropertyValue(it, '');it} log.info "Cleared values for properties $result"
- nmrao8 years ago
Champion Level 1
Here is another variation. Below uses closure to remove properties and user can still pass the condition(as closure) dynamically while calling.
You do not see literally any IF condition
def propTestStep = context.testCase.testSteps['Properties'] def clearPropertyValues = { closure -> propTestStep .propertyNames .findAll( closure ) .collect{ propTestStep.setPropertyValue(it, '');it} } //Clear all the property values if Stop property value is T and do not clear its value and passing conditions as closure log.info "Cleared values for properties ${clearPropertyValues{ it != 'Stop' && 'T' == propTestStep.getPropertyValue('Stop')}}"