Sunday, March 10, 2019

TestNG Tutorial | TestNG Framework with Selenium : How to Install TestNG in Eclipse IDE for Selenium WebDriver

In this tutorial, We will learn how to install and configure TestNG with Eclipse to use TestNG framework in automating scripts using Selenium WebDriver.



Topics to be covered?
  1. Install TestNG in Eclipse IDE.
  2. Configure TestNg Library with the Selenium Project in Eclipse.

In case you are not aware of TestNG, follow the link - TestNG Introduction




Install TestNG in Eclipse IDE

Note - Most of the times TestNG is pre-installed with the Eclipse IDE. So you don't need to do this step.

How to Verify?

Steps: Right click on the Project -> Click on the Build Path -> Click on Configure Build path -> Click on 'Add Library' -> Verify 'TestNG' option as shown in the image below.










If the 'TestNG' option is available as shown in the image above, it means TestNG is pre-installed in the Eclipse IDE.


If Not, then??

Follow below steps to Install TestNG in Eclipse IDE.

  1. Launch Eclipse.
  2. On the menu bar, click Help.
  3. Choose the "Eclipse Marketplace..." option.
  

   
     4. In the Eclipse Marketplace dialog box, type TestNG in the search box and press the search button( magnifying glass) or press Enter key.



   5. Click Install


  6. A new window for feature selection will open, Do not change anything and Click on confirm button.




  7. Click Next again on the succeeding dialog box until you reach the License Agreement dialog.
  8. Click "I accept the terms of the license agreement" then click Finish.


  9. If you encounter a Security warning, just click OK



 10. When Eclipse prompts you for a restart, just click Yes.


  11. After the restart, verify if TestNG was indeed successfully installed. Click Window > Preferences and see if TestNG is included on the Preferences list.




Thus, TestNG is installed in Eclipse IDE.





Configure TestNg Library with the Selenium Project in Eclipse

After Installation of TestNG in Eclipse IDE, We need to configure TestNG Library in our Project(Created In Eclipse) to use the annotations and various useful features provided by TestNG framework.

Click on the below Video URL to configure TestNG Library -

Configure TestNG Library in Eclipse IDE



This is all about how to install and configure TestNg in Eclipse IDE.
In this next tutorial, we will see how to run a selenium test case using TestNG Framework.























Saturday, March 9, 2019

TestNG Tutorial | TestNG Framework with Selenium : Advantages, Annotations | TestNG VS JUnit

In this tutorial, I am going to cover the Introduction to TestNG and its uses in Selenium.



Topics to be covered?
  • What is TestNG?
  • Advantages of TestNG.
  • Annotations of TestNG.
  • Difference between JUnit and TestNG.







TestNG is a testing framework which is used to design and maintain test scripts efficiently and generate test execution results in the form of HTML report. It covers a wide range of testing from Unit testing to end-to-end testing.


Advantages - 

  1. It provides effective HTML report that explains test execution result.
  2. It allows parallel execution of test cases.
  3. It supports parameterization using @parameters annotation.
  4. It provides flexibility to prioritize test cases.
  5. It provides flexibility to ignore the execution of test cases.
  6. It provides assertions to examine the expected and actual outcome.
  7. It supports grouping of test cases.
  8. It supports Data Driven Testing using @DataProvider annotation.



Annotations in TestNG – 

  1. @BeforeSuite – Method under this annotation will execute before the execution of all the tests in the suite.
  2. @AfterSuite – Method under this annotation will execute after the execution of all the tests in the suite.
  3. @BeforeClass – Method under this annotation will execute before the execution of first @test annotation.
  4. @AfterClass – Method under this annotation will execute after the execution of all @test annotation.
  5. @BeforeMethod – Method under this annotation will execute before the execution of each @test annotation.
  6. @AfterMethod – Method under this annotation will execute after the execution of each @test annotation.
  7. @Test – Defines a particular functionality of the application.
  8. @BeforeTest – Method under this annotation will execute before the execution of first @test annotation.
  9. @AfterClass – Method under this annotation will execute after the execution of all @test annotation.

JUnit

It is also a testing framework like TestNG. However, TestNG has some more useful features compared to JUnit. So we can say TestNG is the enhanced version of JUnit.


Similarities between JUnit and TestNG

  • Annotations - Both have similar annotations(@Test, @BeforeClass, @AfterClass), Almost similar annotations(TestNG has @BeforeMethod and @AfterMethod, similarly JUnit has @Before and @After).
  • Annotation to set TimeOut - Both have @Test(timeOut = 1000) in miliseconds.
  • Annotation to Ignore Test - TestNG has @Test(enabled=true) and JUnit has @Ignore.
  • Annotation for Exception - TestNG has @Test(expectedExpecptions=ExceptionName.class) and JUnit has @Test(expected=ExceptionName.class)

Dis-similarities between JUnit and TestNG

  • Annotations - Unlike TestNG, JUnit does not provide @BeforeSuite, @AfterSuite, @BeforeTest and @AfterTest annotations.
  • TestNG provides Grouping of test cases whereas JUnit does not.
  • TestNG provides parallel execution of test cases whereas JUnit does not.
  • Achieving Parametrization in JUnit is more complex than that of TestNG.
  • TestNG provides Dependency of a method on other methods functionality of test cases whereas JUnit does not.