TestNG Framework in Selenium

TestNG Framework in Selenium

TestNG framework in Selenium is a testing framework and the advanced version of JUnit testing framework.

  • The limitations which are identified in JUnit, all are overcome and also given added advantages.
  • It is an add-on to the eclipse. Also in latest version of eclipse, TestNG has been pre-installed.

But if somehow it has not been installed in eclipse then I have described TestNG installation steps in eclipse below.

Steps to install TestNG:

  1. Go to Eclipse >> click on Help >> Select Install New Software.
  2. Click on Add >> give name as TestNG and give the location as ‘http://beust.com/eclipse’ >> click on OK.
  3. Check the checkbox at TestNG >> click on NEXT button >> again click on NEXT.
  4. Click on the Radio button of The Term of License agreement >> click on Finish >> click on OK. On warning message, click on Yes to Restart eclipse.
  5. Now in Eclipse, right click on the project, you will get TestNG option in the option list.


How to use Webdriver with TestNG in eclipse?

  1. Take a TestNG class by right clicking on the project >> click on TestNG >> select Create TestNG
  2. Click on the Browse button at Source folder >> expand the Selenium Automation Project >> Select src >> click on OK
  3. Give the Package Name as TestNG_Project01 >> give the Class Name as Test_Project >> check the check-boxes @before test and @after test >> click on Finish.


TestNG Execution Flow (Life Cycle):

  • When we run the script initially, it invokes the @before test method then executes all the @test methods in alphabetical order then finally it executes @after test
  • Once the execution is completed, it will provide the results in two formats
  1. Console
  2. It creates a Result file under the project folder of Workspace.
  • @before: It contains setup method where it acts as a Pre – Condition.When we run the script, setup method will be executed initially.
  • @test: It represents the test scenario, where it contains the test steps.It is responsible for execution, it acts as a main method.
  • @after: It contains tear down method, which is responsible to stop the execution.

3 Thoughts on TestNG Framework in Selenium

  1. Perfect update of captchas regignizing package “XEvil 4.0”:
    captcha solution of Google (ReCaptcha-2 and ReCaptcha-3), Facebook, BitFinex, Bing, Hotmail, SolveMedia, Yandex,
    and more than 8400 another types of captchas,
    with highest precision (80..100%) and highest speed (100 img per second).
    You can use XEvil 4.0 with any most popular SEO/SMM software: iMacros, XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

    Interested? There are a lot of demo videos about XEvil in YouTube.


    Good luck!


  2. TestNG framework stirred from NUnit and JUnit but presenting some new functionalities that make it much easier and powerful to use. It is an open source automated testing framework; in which NG means Next Generation. TestNG is much more influential than JUnit but is inspired by JUnit.

    There are a large number of advantages but from Selenium perspective, the major advantages of TestNG are:

    1. It gives the facility to produce HTML Reports of implementation.

    2. Annotations have made testers’ life easier.

Leave a Comment