Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 14, 2016

TestNG Annotations





Annotation is a feature introduced in Java 5 and is used to add metadata to Java source code. This will allow you to add information to an existing data object in your source code. It can be applied for Classes, Methods, Variables and Parameters. Java allows users to define their own annotations too. TestNG made use of the same feature to define its own annotations. TestNg Annotations will direct the execution flow of the program.

The following is a table containing information about all the annotations in the TestNG and a brief description of them:

AnnotationDescription
@BeforeSuiteThe annotated method will be executed Before any tests declared inside the TestNG suite
@AfterSuiteThe annotated method will be executed After any tests declared inside the TestNG suite
@BeforeTestThe annotated method will be executed Before test section declared inside the TestNG suite
@AfterTestThe annotated method will be executed After test section declared inside the TestNG suite
@BeforeGroupsThe annotated method will be executed Before any of the test method belongs to specified group
@AfterGroupsThe annotated method will be executed After any of the test method belongs to specified group
@BeforeClassThe annotated method will be executed Before any of the test method of a test class.
@afterClassThe annotated method will be executed After any of the test method of a test class.
@BeforeMethodThe annotated method will be executed Before each test method
@AfterMethodThe annotated method will be executed After each test method
@DataProviderMarks a method as a data providing method for a test method. The said method has to return an Object double array (Object[ ][ ]) as data
@FactoryMarks a annotated method as a factory that returns an array of class objects (Object[ ]). These class objects will then be used as test classes by TestNG. This is used to run a set of test cases with different values
@ListenersApplied on a test class. Defines an array of test listeners classes extending org.testng.ITestNGListener. Helps in tracking the execution status and logging purpose.
@ParametersThis annotation is used to pass parameters to a test method. These parameter values are provided using the testng.xml configuration file at run time
@TestMarks a class or a method as a test method. If used at class level, all the public methods of a class will be considered as a test method




Share this post: on Twitter on Facebook

Adding Methods to testng.xml file Before And After Annotations

Related Posts

Excel to DataProvider

TestNG

Read data from Excel to DataProvider in Selenium

Running TestNG programmatically

TestNG

Running TestNG Tests Programmatically

EXECUTING ONLY FAILED TESTS

TestNG

Executing Only Failed Tests in TestNG

Capture Screenshot for Failed Tests

TestNG

Capture Screenshot for Failed Tests in TestNG

Preserve Order in TestNG

TestNG

Preserve Order in TestNG

PRIORITIZING TESTS

TestNG

Prioritizing Tests in TestNg

EXECUTE MULTIPLE XML FILES

TestNG

Execute Multiple XML files in TestNG

CUSTOM REPORTER IN TESTNG (1)

TestNG

Custom Reporter in TestNG

CUSTOM LOGGER IN TESTNG

TestNG

Custom Logger in TestNG

ASSERTIONS

TestNG

TestNG Assertions

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025