Error using logic IF else

hallo …i.need help using logic if else condition
why IF condition return false but still execute the script in IF Blok?

2 Likes

How do you know it returns false?

I’m assuming you are just testing how to program an if statement. By your own code, the contents of “var1” is true and that is why it moves into your if block. The error is likely because you are trying to print a boolean instead of a String. So, how about below?

var1 = ...
if (var1) { // you don't need to compare to true if var1 is a boolean condition
    println(var1.toString())   // here we cast the boolean to a String
} 
// and if it is not present, do you want your program to hang????
WebUI.closeBrowser()

I think his error is because he said

system.out.println(var1);

instead of

System.out.println(var1);

I am able to print the boolean just fine with the latter… No need to convert to String

Also, as your code shows, he doesn’t even need the system.out at the beginning.

I doubt he even needs to (conditionally) close the browser at the end of the test case (that concern is something that I would move to a Test Listener, but I digress)…

UPDATE: the more I look at his code, the more I see that he could (and probably should) move out of the test case, or otherwise change up:

  • the opening of the browser (should we really be copying and pasting this into every test case?)
  • setting of the password field via plaintext (use encrypted text method instead).
  • the entire if-statement nonsense. Just fail the damn test case (FailureHandling.STOP_ON_FAILURE)!
3 Likes

Thanksss ----> System.out.println(var1); its work

This topic was automatically closed 270 days after the last reply. New replies are no longer allowed.