Selenium - 执行selenium.stop()时出现异常

时间:2009-09-13 12:41:52

标签: selenium

我正在使用Selenium进行Web应用程序测试。完成所有测试后,当执行命令“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());
}

}

2 个答案:

答案 0 :(得分:3)

看起来您在关闭浏览器会话的命令之前关闭了Selenium服务器。尝试用selenium.shutDownSeleniumServer();

注释掉这一行

答案 1 :(得分:1)

我得到了同样的错误。我清除了我的jar文件并重新添加它们,异常消失了。

相关问题