I'm using selenium to send HTTP requests to an HTTP server and I'm getting the following error after closing and reopening the connection from the test code via the same IP/port (127.0.0.1:8080). I'm pretty sure that the HTTP server application is closing the server socket on exit however I'm not so sure that the test (client) code is closing the socket.
My RemoteWebDriver implementation is below and I'm guessing that it might need to override stopClient()
in order to close the socket but with what?
public class MyWebDriver extends RemoteWebDriver {
public MyWebDriver(URL url, Capabilities desiredCapabilities) {
super(new MyCommandExecutor(url), desiredCapabilities);
}
public Response sendCommand(String command){
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("command", command);
Response response = execute("sendCommand", parameters);
return response;
}
}
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40' System info: host: '...', ip: '172.27.3.221', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.1', java.version: '1.7.0_67' Driver info: driver.version: MyWebDriver at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593) at
...
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:8080 [/127.0.0.1] failed: Connection refused
PS: I should mention that the client code can reconnect to the server after 30 seconds or so have elapsed - the OS must be releasing the socket after that time:Java process on Mac OSX does not release socket