Wednesday, February 27, 2013

Selenium :Assersions (Skipping @Test after a Step Fails )

 

Assersions

 

  • assertTrue will fail if the second parameter evaluates to false (in other words, it ensures that the value is true). 
  • assertFalse does the opposite.
Example:
assertTrue("This will succeed.", true);
assertTrue("This will fail!", false);

assertFalse("This will succeed.", false);
assertFalse("This will fail!", true);









Important Types :
  1.     Assert.assertequals("good","god");         o/p: Failed
  2.     Assert.assertTrue("Message " ,4>8 );     o/p-Failed     some message
  3.     Assert.assertFalse("Message " ,8<9 );    o/p-Failed     some message

Note : RunAs>TestNg

Advantages :
Used to report Pass and Fail

Disadvantage:
I have illustrated with the example below.

The file contains 2 @Test ,one having "Assert" statement .If the control encounters failure from Assert statement,then the control will report failure, Skip all the following lines in the current test and jump to the next test.

Overcome :
Use Listerners


//------------------------------------------------------------------------------------------------
package package_name;

import org.testng.Assert;

import org.testng.SkipException;

import org.testng.annotations.BeforeMethod;

public class Test

{

@org.testng.annotations.Test

public void test1()

{

Assert.assertEquals(1, 2);

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

}

@org.testng.annotations.Test

public void test2()

{

System.out.println("Testing 2");

}

}

No comments:

Post a Comment