【问题标题】:Selenium - Exception while executing selenium.stop()Selenium - 执行 selenium.stop() 时出现异常
【发布时间】:2010-11-27 21:48:24
【问题描述】:

我正在使用 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());
}

}

【问题讨论】:

  • 如何以您编辑的方式发布问题。
  • 您可以通过将行缩进 4 个空格来格式化代码示例。
  • 你有调用停止命令的代码示例吗?此错误看起来像是在未运行的会话或服务器上调用了停止。

标签: selenium


【解决方案1】:

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

【讨论】:

【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-07
    • 2016-10-03
    相关资源
    最近更新 更多