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 3, 2019 in Selenium by Sharman
937 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, 2019 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,460 points
8,094 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
16,417 views
0 votes
1 answer
+1 vote
2 answers
0 votes
2 answers

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,500 points
13,771 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,187 views
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,910 points
7,262 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,901 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, 2019 in Selenium by Abha
• 28,140 points
814 views
0 votes
1 answer

How to pass parameter through testng.xml file to a test case in Selenium Webdriver?

Hello Revathi, to pass parameter through testng.xml ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,140 points
7,688 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP