Assert.assertTrue | Selenium Forum
M
Posted on 08/09/2015
Hi all,

Facing problem While using Assert.assertTrue. Find the code below

System.out.println("Line 1");
try{

Assert.assertTrue(5>6, "CONDITION FAILED" );

}catch(Throwable t)
{
System.out.println("caught exception");
}
System.out.println("Line 2");


output am getting is
Line 1
caught exception
Line 2

But it is not printing CONDITION FAILED, since condition mentioned in assertion is false.

M
Replied on 08/09/2015

you have caught the exception so it won't print "CONDITION FAILED" .


M
Replied on 09/09/2015

Thanks for quick reply,

But i want to print all the three Line 1,CONDITION FAILED and Line 2

So i am using below code

System.out.println("Line 1");

Assert.assertTrue(5>6, "condition fails" );

System.out.println("Line 2");
Then output is

Line 1
Exception in thread "main" java.lang.AssertionError: condition fails expected [true] but found [false]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertTrue(Assert.java:42)
at niit.expWait.main(expWait.java:15).



It is not even printing CONDITION FAILED.


M
Replied on 09/09/2015

Hi Ashish,

Gentle reminder

Thanks for quick reply,

But i want to print all the three Line 1,CONDITION FAILED and Line 2

So i am using below code

System.out.println("Line 1");

Assert.assertTrue(5>6, "condition fails" );

System.out.println("Line 2");
Then output is

Line 1
Exception in thread "main" java.lang.AssertionError: condition fails expected [true] but found [false]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertTrue(Assert.java:42)
at niit.expWait.main(expWait.java:15).



It is not even printing CONDITION FAILED.


M
Replied on 09/09/2015

Exception in thread "main" java.lang.AssertionError: [color=#FF0000:7e7purbj]condition fails [/color:7e7purbj]expected [true] but found [false]"

condition fails is written.


M
Replied on 09/09/2015

Hi,

But i want to print all the three, i.e
Line 1
CONDITION FAILED and
Line 2

Just like VERIFY,
Verify: If verify is used then the test case will not abort even if the
verify fails. It will continue executing and log the failure for the failed
conditions.

Pls help me


M
Replied on 11/09/2015

Then you have to use listeners
I have explained it in video 9/20