Forum Discussion

trans-am's avatar
trans-am
Occasional Contributor
2 years ago

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}
}

  • 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's avatar
      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