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:
- Go to Eclipse >> click on Help >> Select Install New Software.
- Click on Add >> give name as TestNG and give the location as ‘http://beust.com/eclipse’ >> click on OK.
- Check the checkbox at TestNG >> click on NEXT button >> again click on NEXT.
- 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.
- 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?
- Take a TestNG class by right clicking on the project >> click on TestNG >> select Create TestNG
- Click on the Browse button at Source folder >> expand the Selenium Automation Project >> Select src >> click on OK
- 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
- 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.