Types and Hierarchy of TestNG Annotations
These are the types of TestNG Annotations
Let’s Elaborate each one by one:
- BeforeSuite: @BeforeSuite is one of the TestNG Annotations. As the name defines, @BeforeSuite is executed before the execution of all the test cases inside a TestNG Suite.
- AfterSuite: @AfterSuite is one of the TestNG Annotations. As the name defines, @AfterSuite is executed after the execution of all the test cases inside a TestNG Suite.
- BeforeTest: @BeforeTest is one of the TestNG Annotations. As the name defines, @BeforeTest is executed before the execution of all the @test annotated methods inside a TestNG Suite
- AfterTest: @AfterTest is one of the TestNG Annotations. As the name defines, @AfterTest is executed after the execution of all the @test annotated methods inside a TestNG Suite.
- BeforeClass: @BeforeClass is one of the TestNG Annotations. As the name defines, @BeforeClass is executed before all the methods of the current class start their execution.
- AfterClass: @AfterClass is one of the TestNG Annotations. As the name defines, @AfterClass is executed after all the methods of the current class finish their execution.
- BeforeMethod: @BeforeMethod is one of the TestNG Annotations. As the name itself defines, @BeforeMethod is executed before each test method within a test class. Suppose there are n test methods within a test class, then n times @BeforeMethod annotated method will be invoked.
- AfterMethod: @AfterMethod is one of the TestNG Annotations. As the name defines, @AfterMethod is executed after each test method within a test class. Suppose there are n test methods within a test class, then n times @AfterMethod annotated method will be invoked.
- BeforeGroups: @BeforeGroups is one of the TestNG Annotations. When you annotate a method with @BeforeGroups, TestNG ensures that this method is invoked before any test method belonging to the specified groups is executed.
- AfterGroup: @AfterGroups is one of the TestNG Annotations. As the name defines, @AfterGroups should be executed after all the test methods belonging to a specified group have been run.
TestNG Annotations in Selenium Webdriver with Examples
TestNG is a testing framework widely used in Selenium WebDriver for automation testing. It provides a wide range of annotations that help in organizing and controlling the flow of test cases. TestNG learns from JUnit and NUnit, making itself better by adding new features that make testing easier and more effective. One of these improvements is the use of annotations.
Table of Content
- What are TestNG Annotations?
- Types and Hierarchy of TestNG Annotations
- Working on TestNG Annotations
- Conclusion
- FAQs on TestNG Annotations in Selenium Webdriver
Contact Us