tags:

views:

1238

answers:

1

I am using Selenium for web application testing. After having finished all the testing, when the command "selenium.stop()" is executed I get the following exception:

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

Here's is code which is executing the stop() command

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());
}

}
+1  A: 

It looks like your shutting down the Selenium server before the command to close the browser session. Try commenting out the line with selenium.shutDownSeleniumServer();

Dave Hunt
You solved my problem.Thanks
Yatendra Goel
Kindly look at my other selenium-related issue at http://stackoverflow.com/questions/1418082/selenium-can-i-hide-the-browser/1419676#1419676
Yatendra Goel