我想將常用方法分組到一個文件中並使用它。例如,使用硒登錄頁面可能會多次使用。在類A中定義並在類B中調用它。但是,它會引發空指針異常。發佈硒代碼維護
類A有
public void test_Login() throws Exception
{
try{
selenium.setTimeout("60000");
selenium.open("http://localhost");
selenium.windowFocus();
selenium.windowMaximize();
selenium.windowFocus();
selenium.type("userName", "admin");
selenium.type("password", "admin");
Result=selenium.isElementPresent("//input[@type='image']");
selenium.click("//input[@type='image']");
selenium.waitForPageToLoad(Timeout);
}
catch(Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
}
與所有其他Java語法
在B類
public void test_kk() throws Exception
{
try
{
a.test_Login();
}
catch(Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
}
與所有的語法。
當我執行B類,我得到這個錯誤,
java.lang.NullPointerException
at A.test_Login(A.java:32)
at B.test_kk(savefile.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.j
ava:212)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at junit.textui.TestRunner.run(TestRunner.java:77)
at B.main(B.java:77)
我希望有人必須有嘗試過這一點。我可能會錯過這裏的東西。
確保硒服務器已啓動,並且在運行此代碼之前啓動硒瀏覽器 – 2010-03-16 08:55:20
我已經完成了該操作。它打開瀏覽器,但沒有把地址放在那裏。 – Rajasankar 2010-03-16 09:17:50
你可以添加你如何設置這個問題嗎? – AutomatedTester 2010-03-16 11:14:06