Test base class inheritance

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Test base class inheritance

Sebastian Hüttermann
I'm currently migrating from JUnit based selenium test to testNG based selenium tests. I do have a base class for my tests since I'm using a selenium grid. In this base class a parameter object is built, the selenium webdriver is created and a reporter object is created.

public abstract class SeleniumBaseTest {
protected final SeleniumTestParameter parameter;
protected ExtentReports reporter;
protected WebDriver driver;
@Parameters({"initialPage", "username", "password", "hubURL", "browser", "os"})
public SeleniumBaseTest(
final String initialPage,
final String username,
final String password,
final String hubURL,
final String browser,
@Optional("os") final String os) {
final SeleniumTestParameter.SeleniumTestParameterBuilder builder = SeleniumTestParameter.builder();
if(os != null) { builder.os(Platform.fromString(os)); }
this.parameter = builder.build();
@BeforeClass(alwaysRun = true)
public void reportInit() {
this.reporter = TestUtilFactory.getReporter();
@BeforeMethod(alwaysRun = true)
public void driverInit() throws MalformedURLException {
this.driver = TestUtilFactory.driver(this.parameter);
@AfterMethod(alwaysRun = true)
public void driverCleanUp() {
if(this.driver != null) { this.driver.quit(); }
@AfterClass(alwaysRun = true)
public void reporterCleanUp() {
if(this.reporter != null) { this.reporter.flush(); }

My Test classes inherit from this base class:

public class LoginPageTest extends SeleniumBaseTest {

public LoginPageTest(final String initialPage, final String username, final String password, final String hubURL, final String browser, final String os) {
super(initialPage, username, password, hubURL, browser, os);
@Test(groups = "basics", dependsOnGroups = "fundamentals")
public void loginTestIncorrect() {
// incorrect credentials shoudln't work...
@Test(groups = "fundamentals")
public void loginTestCorrect() {
// correct credentials should work...

When I'm running this test with

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="suite" verbose="999">
<test name="RegressionTest">
<class name="org...LoginPageTest"/>

I get the error 

"[TestNG] No tests found. Nothing was run"

However, when I actually copy "the contents of the base class into my test class" (you know what I mean) everything seems to work fine. Since I have a lot of test classes copying the contents (aka getting rid of the Base Class) is not really an option. Any ideas? What can I do?

Thanks, Sebastian

You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.