• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Selenium
  • Manual Testing
  • SQL Tutorial For Beginners
  • Difference
  • Tools
  • Contact Us
  • Search
SoftwareTestingo » Selenium » Free Selenium Tutorial » TestNG Method Overriding – With Sample Example

TestNG Method Overriding – With Sample Example

Last Updated on: November 30, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • TestNG Method Overriding Example

TestNG Method Overriding: Earlier, we have seen how we can achieve method overloading in a TestNG class, and similarly, in this post, we are going to see how we can make method overriding in a testNG class.

As we all know about method overriding is nothing but creating a method in child class which is already a similar method in the parent class is called method overriding. If you want to know the complete post about this, you can use this method overriding the link.

TestNG Method Overriding Example

So let us discuss how we can achieve method overriding in Java:

First Creat a superclass like below:

package InheritanceInTestNG;
import org.testng.annotations.Test;
public class SuperTestNgClass 
{

   @Test
   public void superTestNgMethod()
   {
      System.out.println(“Super testng method”);
   }

   @Test
   public void superTestNgAnotherMethod()
   {
      System.out.println(“Super testng Another method”);
   }
}

Create another child class like below:

package InheritanceInTestNG;
import org.testng.annotations.Test;
public class SubTestNGClass extends SuperTestNgClass
{

   // Overriding super class testng methods
   @Test
   public void superTestNgMethod()
   {
      System.out.println("Super testng method overrriden in sub class");
   }

   // Method of sub class
   @Test
   public void subTestNgMethod()
   {
      System.out.println("Sub testng method");
   }
}

Now create a testng.xml file for the child class and run that. If you take a look at the output, then you will find out that it will execute all the methods of child class with the overridden method.

In our earlier discussion, we have seen that TestNG prioritizes and executes the test cases if we run separately both super and subclasses. But if we override, then all methods of subclass with the overridden method will be executed, but the parent method of superclass will be ignored.

Source: link

    XPath In Selenium
    XPath in Selenium WebDriver: Complete Tutorial
    Selenium Introduction
    Selenium Introduction – Different Components [WebDriver & Grid]
    Upload & Download a File
    How to Upload & Download a File using Selenium Webdriver
    Timeout Attributes
    Timeout Attributes Of @Test Annotation In TestNG
    TestNG Report
    TestNG Report Generation in Selenium WebDriver
    BeforeClass & BeforeSuite TestNG Annotation
    Difference Between BeforeClass & BeforeSuite TestNG Annotation
    TestNG Method Return Statement
    TestNG Method with Return Statement
    Selenium Tutorial
    Selenium Tutorial Java
    Automation Environment Setup
    Automation Environment Setup – Selenium WebDriver
    Link Text and Partial Link Text Locator in Selenium WebDriver
    Link Text and Partial Link Text In Selenium WebDriver

    Filed Under: Free Selenium Tutorial

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Footer

    Java Tutorial for Beginners | Selenium Tutorial | Manual Testing Tutorial | SQL Tutorial For Beginners | GitHub Tutorial For Beginners | Maven Tutorial

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers