Assert = false and log.info to the console
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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}
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can I ask, why go to the effort of building the IF to assert true/false? Why not "assert not null"?
