Make Selenium Easy

TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

Hello Folks,

We have seen how inheritance works in TestNg classes in this post.  In this post, we will see how overriding works in inherited TestNG classes.

Create a super class as below:

Now create a sub class where we will override one method from super class as below:

Let’s run subclass as a testng test:

 

You can see that only overridden methods in subclass got executed. In this post , we learnt that TestNG prioritized and execute methods of super class and subclass separately. But if some methods are overridden, only overridden method will be executed and parent method of super class will be ignored.  If you have better understanding of overriding concept in java, then it is similar to calling super class method using sub class reference.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

2 thoughts on “TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

  1. System.out.println(“hello”); is working under @Test method. but

    driver.findElement(By.cssSelector(“.ml-auto>li:nth-child(2)>.index-nav-link>span”)).click();
    driver.findElement(By.id(“account_email”)).sendKeys(“muneebakhtaar@gmail.com”);
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
    driver.findElement(By.xpath(“//input[@name=’commit’]”)).click();

    is not working ashowing an error.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

TestNG Tutorials 20: Overriding Of Test Methods In TestNG Class

by Amod Mahajan time to read: 1 min
2
%d bloggers like this: