TestNG Inheritance: As we have already learned how testNG supports both method overloading and method overriding in a testNg class. Now we are going to discuss one more important oops concept inheritance with TestNG.
If you can recall that inheritance is nothing a process by which one class acquires the data member and member function of other class. If you don’t know in detail about inheritance, then no need to worry because we have already covered about inheritance in Java in detail there.
TestNG Inheritance Implementation
Let’s try to find out is TestNg support the feature inheritance or not, with some simple program:
Superclass:
package InheritanceInTestNG; import org.testng.annotations.Test; public class SuperTestNgClass { @Test public void superTestNgMethod() { System.out.println(“Super testng method”); } }
Child Class with Extends Superclass:
package InheritanceInTestNG; import org.testng.annotations.Test; public class SubTestNGClass extends SuperTestNgClass { @Test public void subTestNgMethod() { System.out.println("Sub testng method"); } }
Now create a test suite that has both super and child classes and execute that suite.
As in the output, you can say that we have got both class methods are executed. As a part of the superclass, the method is executed, and as the child class has both super and child class methods, the output has all the methods, which mean both super and child class methods.
Source: link
can the order of execution of the tests in child class be controlled , as in when child class runs can we trigger the super class function first and then the child class
While executing the same above code ..FAILED CONFIGURATION: @AfterClass test1
java.lang.NullPointerException: Cannot invoke “org.openqa.selenium.WebDriver.findElement(org.openqa.selenium.By)” because “ui.test1” is null
can you share your codes