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

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

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