Ask a Question

Assert = false and log.info to the console

SOLVED
trans-am
Occasional Contributor

Assert = false and log.info to the console

When firstName is null I would like to assert false and print log.info but in "else" part I cannot print log.info to console. Any thoughts?

Following piece of script.  

======================================================

def firstName1 = (json.nameList[0].firstName) // take Name
if ( firstName1 != null ) { // firstName1 has a value. It's not null
{assert true}
log.info("firstName = " + firstName1) // print to console
}
else { log.info("firstName = " + firstName1)
{ assert false}
}

3 REPLIES 3
Shashavali
Contributor

its throwing an error at log.info in else. 

 

you are trying to print the value which null thats why its giving error.

 

you can use log.info ("firstname is null")

 

 

 

 

 

trans-am
Occasional Contributor

Actually it's not giving error. It's just no executed. If I comment assert out, I will get log.info to the console

======================================================

def firstName1 = (json.nameList[0].firstName) // take Name
if ( firstName1 != null ) { // firstName1 has a value. It's not null
{assert true}
log.info("firstName = " + firstName1) // print to console
}
else { log.info("firstName = " + firstName1)
// { assert false}
}

======================================================

Then I will see output 

Fri Feb 17 15:01:15 CET 2023:INFO:firstName = null

 

 

 

ChrisAdams
Community Leader

Hi,

 

Can I ask, why go to the effort of building the IF to assert true/false?  Why not "assert not null"?

 

https://community.smartbear.com/t5/ReadyAPI-Questions/How-to-assert-for-a-quot-not-null-quot-respons...

 

cancel
Showing results for 
Search instead for 
Did you mean: