Forum Discussion

Kryotonian's avatar
Kryotonian
Occasional Visitor
3 years ago

Unable to check 'blank' property

So, I'm working on this project where initially the property value is blank. But when I run the test suite and value is received as response at the end of the execution.
My goal is to make a list of all the values received after multiple execution.
I added the following code as groovy script in the script assertion of the last step where value is received:
If(propertyValue =="")
{
Set property as value received in the response

}

Else{
Set property = current property value + new value received in response
}

But unfortunately it's not working and else part is getting executed in all cases.

1 Reply

  • KarelHusa's avatar
    KarelHusa
    Champion Level 3

    Kryotonian ,

    there are many options, how to check the string, I would recommend:

     

    if (! myString?.trim() ) {

    Which checks, whether the string (please note the logical not !):

    • is null or
    • is empty or 
    • contains only whitespace chars

     

    The usage could be:

     

    if (! context.testCase.getPropertyValue('myProperty')?.trim()) {
    log.info("Empty, whitespaces or null")
    }

     I would avoid comparing with == in similar cases as it has different meaning in Groovy and Java and does not check the whitespaces.

     

    Best regards,

    Karel