0
votes

I have following constructor in a public class:

public LoginPage(Browser browser, Logger logger) throws GeneralLeanFtException {
    super(browser, logger);
}

browser and logger variables are defined in BasePage class, which is extended by this class.

public class BasePage {
    protected Browser browser;
    protected Logger logger;

    public BasePage(Browser browser,Logger logger) throws GeneralLeanFtException {
        this.browser = browser;
        this.logger = logger;
    }
}

I get following error message when execute it with TestNG.

either make it static or add a no-args constructor to your class

Error stack:

throws com.hp.lft.sdk.GeneralLeanFtException,java.lang.InterruptedException: either make it static or add a no-args constructor to your class at org.testng.internal.Utils.checkInstanceOrStatic(Utils.java:795) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:40) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:348) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305) at org.testng.SuiteRunner.run(SuiteRunner.java:254) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057)

Class from test is executed:

@Test
public class LeanFTest {
    public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
        TestNG testNG = new TestNG();
        testNG.setTestSuites(Arrays.asList("testng.xml"));
        testNG.setPreserveOrder(true);
        testNG.run();
    }

}
2
You question is not clear. Can you add your test class and error stack?Shaunak Patel
@ShaunakPatel : I updated question.plaidshirt

2 Answers

0
votes

Protected variable can be seen by this class, classes in the same package and classes which extend that class.

static variable exists at class level, it does not exist separately for each instance and it does not have an independent existence in classes which extend class.

 public class BasePage {
        protected static Browser browser;
        protected static Logger logger;

        public BasePage(Browser browser,Logger logger) throws GeneralLeanFtException {
            this.browser = browser;
            this.logger = logger;
        }
    }

try like this by making protected variables as protected static

0
votes

Not sure but looking exception message, and source code it seems you need to have no argument constructor in your class.

Can you add no argument constructor in your BasePage and LoginPage class and check?