开发者

Calling test from another class of selenium in java

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.typ开发者_如何学JAVAe("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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜