2009-09-13 114 views
2

我正在使用Selenium進行Web應用程序測試。在已經完成了所有的測試,當命令「selenium.stop()」執行我得到以下異常:Selenium - 執行selenium.stop()時出現異常

java.net.ConnectException: Connection refused: connect 
     at java.net.PlainSocketImpl.socketConnect(Native Method) 
     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 
     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 
     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
     at java.net.Socket.connect(Socket.java:519) 
     at java.net.Socket.connect(Socket.java:469) 
     at sun.net.NetworkClient.doConnect(NetworkClient.java:163) 
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:394) 
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:529) 
     at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:760) 
     at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632) 
     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049) 
     at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373) 
     at com.thoughtworks.selenium.HttpCommandProcessor.getResponseCode(HttpCommandProcessor.java:134) 
     at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:154) 
     at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:97) 
     at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:79) 
     at com.thoughtworks.selenium.HttpCommandProcessor.stop(HttpCommandProcessor.java:242) 
     at com.thoughtworks.selenium.DefaultSelenium.stop(DefaultSelenium.java:111) 
     at seleniumproject.orkut.tearDown(orkut.java:54) 
     at junit.framework.TestCase.runBare(TestCase.java:140) 
     at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212) 
     at junit.framework.TestResult$1.protect(TestResult.java:110) 
E 
     at junit.framework.TestResult.runProtected(TestResult.java:128) 
Time: 63.453 



There was 1 error: 
1) testOrkut(seleniumproject.orkut)java.lang.UnsupportedOperationException: Catch body broken: IOException from cmd=testComplete -> java.net.ConnectException: Connection refused: connect 
     at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:100) 
     at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:79) 
     at com.thoughtworks.selenium.HttpCommandProcessor.stop(HttpCommandProcessor.java:242) 
     at com.thoughtworks.selenium.DefaultSelenium.stop(DefaultSelenium.java:111) 
     at seleniumproject.orkut.tearDown(orkut.java:54) 
     at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212) 
     at seleniumproject.orkut.main(orkut.java:57) 
Caused by: java.net.ConnectException: Connection refused: connect 
     at java.net.PlainSocketImpl.socketConnect(Native Method) 
     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 
     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 
     at junit.framework.TestResult.run(TestResult.java:113) 
     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 
     at junit.framework.TestCase.run(TestCase.java:124) 
     at java.net.Socket.connect(Socket.java:519) 
     at junit.framework.TestSuite.runTest(TestSuite.java:232) 
     at java.net.Socket.connect(Socket.java:469) 
     at sun.net.NetworkClient.doConnect(NetworkClient.java:163) 
     at junit.framework.TestSuite.run(TestSuite.java:227) 
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:394) 
     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 seleniumproject.orkut.main(orkut.java:57) 
     at sun.net.www.http.HttpClient.openServer(HttpClient.java:529) 
     at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:760) 
     at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632) 
     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049) 
     at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373) 
     at com.thoughtworks.selenium.HttpCommandProcessor.getResponseCode(HttpCommandProcessor.java:134) 
     at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:154) 
     at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:97) 
     ... 16 more 

這裏是正在執行的stop()命令代碼

public class orkut extends SeleneseTestCase { 
public void setUp() throws Exception { 
    setUp("https://www.google.com/"); 
} 

    public void testOrkut() throws Exception { 
       Parser parser = new Parser(); 
       try { 
        ....... 
        ....... 
        ....... 
       }catch(Exception ex) { 
       }finally { 
        parser.closeConnection(); 
        selenium.shutDownSeleniumServer(); 
       } 
    } 

    public static Test suite() { 
    return new TestSuite(orkut.class); 
} 
public void tearDown(){ 
    selenium.stop(); 
} 
public static void main(String args[]) { 
    junit.textui.TestRunner.run(suite()); 
} 

} 
+0

如何以您編輯此方式發佈問題。 – 2009-09-13 12:55:44

+0

您可以通過將行縮進4格來格式化代碼示例。 – 2009-09-13 13:07:31

+0

您是否有調用停止命令的代碼示例?此錯誤看起來像是在未運行的會話或服務器上調用stop。 – 2009-09-13 13:09:23

回答

3

它看起來像在關閉瀏覽器會話的命令之前關閉Selenium服務器。嘗試使用selenium.shutDownSeleniumServer()註釋掉該行;

+0

你解決了我的問題。 謝謝 – 2009-09-14 10:33:50

+0

請看我的其他硒相關問題 http://stackoverflow.com/questions/1418082/selenium-can-i-hide-the-browser/1419676#1419676 – 2009-09-14 10:34:39

1

我得到了同樣的錯誤。我清理了我的jar文件並重新添加了它們,異常消失了。

相關問題