How to call Selenium to another class : NullPointerException

后端 未结 1 1219
滥情空心
滥情空心 2021-01-23 10:59

How can we cal an object selenium to the other file which has half code of selenium.

In PHP i can by following code.

login($this); ----> login

相关标签:
1条回答
  • 2021-01-23 11:33

    Replace:

    public void testAllTests() throws Exception {
        Library obj1 = new Library();
        obj1.Login();
    }
    

    With:

    public void testAllTests() throws Exception {
        super.Login();
    }
    

    Since your Login class already extends Library it already has the Login() method present in it. What you are currently doing is creating a new Library object which does not run the @Before and hence the Selenium field is not initialised (in the new object).

    When a subclass extends a base class it will inherit its methods. This is a fundamental Java and OOP concept.

    0 讨论(0)
提交回复
热议问题