3

This is my method which call a function from another class Selenium Setup is defined hear.

public void Transfer() throws Exception {
System.out.println("\nTransfer\n");
    selenium.open("/logon/user");
    selenium.windowMaximize();
    login obj1 = new login();
    obj1.testlogin();
            selenium.click("link=TRANSFERS");
    selenium.waitForPageToLoad("80000");

This is the another class which has the function to execute for the above caller. The above setup function has selenium object which should be called hear in library.

public class login extends SeleneseTestCase{


public void testlogin(){


    System.out.println("\nLogin\n");    
    selenium.type("companyID", "abcd");
    selenium.type("j_username", "xyz");
    selenium.type("j_password", "123456");
    selenium.click("submit_logon");
    selenium.waitForPageToLoad("80000");

    }
}   

I am getting the following error

1) Transfer(test)java.lang.NullPointerException
    at login.testlogin(login.java:12)
    at test.Transfer(test.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.j

ava:212) at SampleSuite.main(SampleSuite.java:25)

I am trying to save all function's like login in an library and want to call them as per required in suite but i am unable to pass the pointer of selenium browser to the called function

Can anyone help me to resolve the error

Setup Code as follows :

  public void setUp() throws Exception {
    selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://abc.com/");
    selenium.start();
}

Thanks in advance to all

  • I am also unable to call "selenium" object from one file to another file in java. – lAH2iV Jul 26 '11 at 11:56
  • Use this [Link][1] For your answer. This is the same Issue I Faced [1]: http://stackoverflow.com/questions/6832319/how-to-call-selenium-to-another-class-nullpointerexception/6843288#6843288 – lAH2iV Jul 27 '11 at 11:54
  • Use this [link](http://stackoverflow.com/questions/6832319/) for your answer. This is the same issue I faced (http://stackoverflow.com/questions/6832319/). – lAH2iV Oct 11 '11 at 08:59

1 Answers1

1

Just for simplicity sake, you could basically pass the Selenium object once to your testlogin(Selenium selenium)or you can create a static variable of Selenium = globalinstance and assign it to a variable and create a wrapper in the class that you want to use in testlogin{selenium globalinstance}. Hope this helps as simple solution.

satish john
  • 226
  • 1
  • 6
  • 14