Difference Between BeforeClass & BeforeSuite TestNG Annotation

How BeforeClass & BeforeSuite TestNG Annotation Example In Selenium?

package com.selenium.TestNG;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestNG_BeforeClass 
{
   @BeforeSuite
   public void openBrowser()
   {
      System.out.println("Browser Opened");
   }
   @BeforeClass
   public void login()
   {
      System.out.println("Login Sucessfully");
   }
   @Test
   public void operation()
   {
      System.out.println("Openration Done");
   }
   @AfterClass
   public void logout()
   {
      System.out.println("Logout Sucessfully");
   }
   @AfterSuite
   public void closeBrowser()
   {
      System.out.println("Browser Closed");
   }
}

Avatar for Softwaretestingo Editorial Board

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment