TestNG Annotations:

 TestNGà  

It is a unit testing framework ->

Selenium + testNG

Browser + testing


Java- Junit/TestNG

Python : Pytest

JS : Mocha/Jasmine

C# : NUnit


  1. 1.      Free and open source
  2. 2.      Easily integrated with selenium
  3. 3.      ReportàHTML: PASS/FAIL, XML report
  4. 4.      Organize test cases
  5. 5.      Prerequisites:
  6. 6.      Test runners->testng.xml
  7. 7.      Parallel Run
  8. 8.      Priority test cases/Ignore tcs
  9. 9.      Invocation count
  10. 10.  testNG listeners : attach screenshot in the report, allure, extends report
  11. 11.  annotations: before steps, after steps (please open before after test close all)
  12. 12.  Data Provider- test data, supply in the form of arrays- one test with 5 diff usr/pws
  13. 13.  Parameters: envoi parameters, configuration parameters
  14. 14.  Easily integrate with Maven
  15. 15.  Retry logic -> if specific test is failed, we can retry –refry failed tc’s
  16.       Testng dependencies:

 

1.      TestNG dependency in pom.xmlà so that I can use all the methods ,classes and annotations from testng in my code.

2.      Add testng plugin in eclipse : so that I can run tc’s from eclipse using testNG

 

Annotations: @->starts with

Orders of Annotations

Before annotations

Test Annotations

After Annotations


BSuite--dbConnections

BTest ---createUser

BClass ---launchBrowser


BeforeMethod ---Login to the app

Test --URL Test---1

AfterMethod --logout

BeforeMethod ---Login to the app

Test --header Test---2

AfterMethod --logout

BeforeMethod ---Login to the app

Test --title Test---3

AfterMethod --logout

AClass --closeBrowser

ATest --deleteUser

ASuite--disconnectwithDB


public class OpenCartTest {

//before annotations-- preconditions to test cases

@BeforeSuite

//1.

public void dbConnections() {

System.out.println("BS--dbConnections");

}

@BeforeTest

//2.

public void createUser() {

System.out.println("BT ---createUser");

}

@BeforeClass

//3.

public void launchBrowser() {

System.out.println("BC ---launchBrowser");

}

@BeforeMethod

//it will start before each and every method

public void login() {

System.out.println("BM ---Login to the app");

}

//Alphabatically it will run @Test -- abcd

@Test

public void titleTest() {

System.out.println("T --title Test");

}

@Test

public void headerTest() {

System.out.println("T --header Test");

}

@Test

public void URLTest() {

System.out.println("T --URL Test");

}

@AfterMethod

//After each and every method

public void logout() {

System.out.println("AM --logout");

}

@AfterClass

public void closeBrowser() {

System.out.println("AC --closeBrowser");

}

@AfterTest

public void deleteUser() {

System.out.println("AT --deleteUser");

}

@AfterSuite

public void disconnectwithDB() {

System.out.println("AS --disconnectwithDB");

}

}


OP:




BS--dbConnections

BT ---createUser

BC ---launchBrowser

BM ---Login to the app

T --URL Test

AM --logout

BM ---Login to the app

T --header Test

AM --logout

BM ---Login to the app

T --title Test

AM --logout

AC --closeBrowser

AT --deleteUser

PASSED: testngSessions.OpenCartTest.URLTest

PASSED: testngSessions.OpenCartTest.titleTest

PASSED: testngSessions.OpenCartTest.headerTest


===============================================

Default test

Tests run: 3, Failures: 0, Skips: 0

===============================================


AS --disconnectwithDB


===============================================

Default suite

Total tests run: 3, Passes: 3, Failures: 0, Skips: 0





Priority :it will execute the test case in ascending order

default priority is 0


Tc's define with no priority will be executed in alphabetical order

Tc's define with no priority will be by default 0

Tc's define with same priority will be exe in alphabetical order


eg: -1,0,1,2,3,4,5



public class PriorityTest {


@Test(priority = 4)

public void aTest() {

System.out.println("a test");

}


@Test(priority = 5)

public void bTest() {

System.out.println("b test");

}


@Test(priority = 3)

public void cTest() {

System.out.println("c test");

}


@Test(priority = 2)

public void dTest() {

System.out.println("d test");


}


@Test(priority = 1)

public void eTest() {

System.out.println("e test");

}

@Test(priority = 999)

public void fTest() {

System.out.println("f test");

}

}


e test

d test

c test

a test

b test

f test


InvocationCount:


@Test(invocationCount=100)

public void welcome() {

System.out.println("Welcome to the world");

}



OP:

Tests run: 1, Failures: 0, Skips: 0

===============================================

Default suite

Total tests run: 100, Passes: 100, Failures: 0, Skips: 0


Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium