Can anyone demonstrate with an example how the TestNG Annotations behave while running a testng.xml file?

0 votes
Can anyone demonstrate with an example how the TestNG Annotations behave while running a testng.xml file?
Jul 2 in Selenium by Sharman
19 views

1 answer to this question.

0 votes

Hey Sharman, TestNG annotations behave in the following manner while running a test file:

package testNGAnnotations;

import org.testng.annotations.AfterClass;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.AfterSuite;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

public class AnnotationsOrder {

        @Test

        public void testCase1() {

            System.out.println("This is the Test Case 1");

        }

        @Test

        public void testCase2() {

            System.out.println("This is the Test Case 2");

        }

        @BeforeMethod

        public void beforeMethod() {

            System.out.println("This will execute before every Method");

        }

        @AfterMethod

        public void afterMethod() {

            System.out.println("This will execute after every Method");

        }

        @BeforeClass

        public void beforeClass() {

            System.out.println("This will execute before the Class");

        }

        @AfterClass

        public void afterClass() {

            System.out.println("This will execute after the Class");

        }

        @BeforeTest

        public void beforeTest() {

            System.out.println("This will execute before the Test");

        }

        @AfterTest

        public void afterTest() {

            System.out.println("This will execute after the Test");

        }

        @BeforeSuite

        public void beforeSuite() {

            System.out.println("This will execute before the Test Suite");

        }

        @AfterSuite

        public void afterSuite() {

            System.out.println("This will execute after the Test Suite");

        }

    }
answered Jul 3 by Sam

Related Questions In Selenium

0 votes
1 answer

How to create a executable jar file for TestNG and the runnnig point should be the Xml file

Use Eclipse Export Wizard. While exporting, select "Create ...READ MORE

answered Aug 24, 2018 in Selenium by Meci Matt
• 9,400 points
1,197 views
0 votes
1 answer

Getting error while running a XML file in TestNG

Hello @Sradha, The synatx of using test is ...READ MORE

answered Dec 26, 2018 in Selenium by Rashmi
340 views
0 votes
1 answer

How can I access the parent of a node with XPath?

Hey Hemant, we can use the double ...READ MORE

answered Jun 23 in Selenium by Anvi
• 10,310 points
25 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
259 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
628 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
257 views
0 votes
1 answer

Can anyone explain the annotations available in TestNG?

Hi Ishika, following annotations are available in ...READ MORE

answered Jun 10 in Selenium by Abha
• 16,440 points
19 views
0 votes
1 answer