11. Q & A - senthilpazhani/SeleniumComplete GitHub Wiki

1. Advantages

  1. Support for annotations
  2. Support for parameterization
  3. It gives the ability to produce HTML Reports of execution
  4. Support for Data Driven Testing using Data providers
  5. Enables user to Grouped & set execution priorities for the test methods
  6. Supports threat safe environment when executing multiple threads
  7. Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse).
  8. Facilitates user with effective means of Report Generation using ReportNG
  9. Concurrent execution of test scripts
  10. Generates Logs

2. Advantages of TestNG over JUnit

  1. Added advance and easy annotations
  2. Execution patterns can be set
  3. Concurrent execution of test scripts
  4. Test case dependencies can be set

3. Hard and Soft Assertions in Selenium

Hard Assertions

Tests immediately fail and stop executing the moment a failure occurs in the assertion. You may want to use a hard assert if you want to verify if you have logged in correctly and fail the test if you haven’t as there is no point in proceeding further if the test if the pre-condition itself fails.

Soft Assertions

Tests don’t stop running even if an assertion condition fails, but the test itself is marked as a failed test to indicate the right result. This is useful if you are doing multiple validations in a form. You may actually want to complete all the validations and fail the test once all validations are complete in case of failures.

  `public class TestNG_SoftAsserts {	`
  	`@Test`
      `public void testSum() {`
	      `SoftAssert sa = new SoftAssert();`
  		`System.out.println("\nRunning Test -> testSum");`
  		`SomeClassToTest obj = new SomeClassToTest();`
  		`int result = obj.sumNumbers(1, 2);`
  		`sa.assertEquals(result, 2);`
  		`System.out.println("\nLine after assert 1");`
  		`sa.assertEquals(result, 3);`
  		`System.out.println("\nLine after assert 2");`
  		`sa.assertAll();`
  	`}`
  `}`
  
  `public class TestNG_Asserts {`
  	
  	`@Test`
  	`public void testSum() {`
  		`System.out.println("\nRunning Test -> testSum");`
  		`SomeClassToTest obj = new SomeClassToTest();`
  		`int result = obj.sumNumbers(1, 2);`
  		`Assert.assertEquals(result, 3);`
  	`}`
  	
  	`@Test`
  	`public void testStrings() {`
  		`System.out.println("\nRunning Test -> testStrings");`
  		`String expectedString = "Hello World";`
  		`SomeClassToTest obj = new SomeClassToTest();`
  		`String result = obj.addStrings("Hello", "World");`
  		`Assert.assertEquals(result, expectedString);`
  		
  	`}`
  	
  	`@Test`
  	`public void testArrays() {`
  		`System.out.println("\nRunning Test -> testArrays");`
  		`int[] expectedArray = {1, 2, 3, 4};`
  		`SomeClassToTest obj = new SomeClassToTest();`
  		`int[] result = obj.getArray();`
  		`Assert.assertEquals(result, expectedArray);`
  		`System.out.println("\nEnd Test -> testArrays");`
  	`}`
  `}`