You are here

TestNG

AttachmentSize
Untitled drawing.jpg39.73 KB

Selenium with TestNG is very famous. Because it is generating reports and It is execute test cases with parallel with TestNG and Grid.

Annotations Function in TestNG

  1. @BeforeMethod
  2. @AfterMethod
  3. @BeforeClass
  4. @AfterClass
  5. @BeforeTest
  6. @AfterTest
  7. @BeforeSuite
  8. @AfterSuite

Annotations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
 
public class GmailTest {
 
 @BeforeSuite // This is executing once before executing all tests 
 public void BeforeSuite(){
     System.out.println("Before Test Suite");
 }
  
 @AfterSuite // // This is executing once after executing all tests 
 public void AfterSuite(){
     System.out.println("After Test Suite");
 }
  
 @Test
  public void TestReciveMail() {
      System.out.println("Recieving Mail");
  }
  
  
  @Test
  public void TestSendMail() {
      System.out.println("Sending Mail");
  }
  
  @BeforeMethod // Before executing every test case
  public void OpenBrowser() {
      System.out.println("Open Browser");
  }
 
  @BeforeTest // Before executing all test cases
  public void ConnecttoDatabase() {
      System.out.println("Connect to Database");
  }
  
  @AfterTest // After executing all test cases
  public void CloseConnectiontoDatabase(){
      System.out.println("Close connection to database");
  }
  
  @AfterMethod // After executing every test case
  public void CloseBrowser() {
      System.out.println("Close Browser");
  }
 
}