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

3
  • I am also unable to call "selenium" object from one file to another file in java. Commented Jul 26, 2011 at 11:56
  • Use this [Link][1] For your answer. This is the same Issue I Faced [1]: stackoverflow.com/questions/6832319/… Commented Jul 27, 2011 at 11:54
  • Use this link for your answer. This is the same issue I faced (stackoverflow.com/questions/6832319). Commented Oct 11, 2011 at 8:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.