简体   繁体   中英

“Implicit super constructor BaseTestMethod() is undefined for default constructor. Must define an explicit constructor” How do i fix this error?

So I have a base class in a base package and I am extending that base class to another class in another package.

In the extended class i get this error: "Implicit super constructor BaseTestMethod() is undefined for default constructor. Must define an explicit constructor". I tried adding the super() but it doesn't solve the issue. Can Someone help.

Base Class:

public class BaseTestSuite{
    public WebDriver driver;

    @Parameters("browserType")
    @BeforeSuite
    public void beforeSuite(String browserType) {

        System.out.println("BaseTestSuite -> Before Test Suite");
        if (browserType.equalsIgnoreCase("firefox")) {
            System.getProperty(DefaultStrings.FIREFOX_DRIVER_KEY, DefaultStrings.FIREFOX_DRIVER_PATH);
            driver = new FirefoxDriver();
        } else if (browserType.equalsIgnoreCase("chrome")) {
            System.setProperty(DefaultStrings.CHROME_DRIVER_KEY, DefaultStrings.CHROME_DRIVER_PATH);
            driver = new ChromeDriver();
        }
    }
}

Extended Class:

public class FlockSignIn extends BaseTestMethod {
    private WebDriver driver;
    private static final Logger log = LogManager.getLogger(FlockSignIn.class.getName());
    static GenericMethods gm;

    public WebDriver getDriver(){
        return driver;
    }

    FlockSignIn(String browserType){
        super browserType;
    }

    @BeforeClass
    public void beforeClass() {

        /*System.out.println("BaseTestSuite -> Before Test Suite");
        if (browserType.equalsIgnoreCase("firefox")) {
            System.getProperty(DefaultStrings.FIREFOX_DRIVER_KEY, DefaultStrings.FIREFOX_DRIVER_PATH);
            driver = new FirefoxDriver();
        } else if (browserType.equalsIgnoreCase("chrome")) {
            System.setProperty(DefaultStrings.CHROME_DRIVER_KEY, DefaultStrings.CHROME_DRIVER_PATH);
            driver = new ChromeDriver();
        }*/

        gm = new GenericMethods(driver);

        gm.maximize();
        driver.get(DefaultStrings.FLOCK_WEB_PREPROD);
        log.info("Opening the webclient");
        driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    }

In BaseTestMethod class, add the constructor

public BaseTestMethod(){
.....

}

Or modify your flockSignIn constructor:

FlockSignIn(String browserType){
    super (param defined in BaseTestMethod's constructor);
    ..
}

There are multiple issues with the implementation:

  1. Parent class name is BaseTestSuite and you are extending BaseTestMethod .

In case of default constructors super() is implicitly called and In case parent has its own overloaded constructor, we need to call super(argument list) and not super argument list

I hope it solves your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM