I am trying to integrate OperaDriver for Java (ver. 0.11) into my test suite. Here's the code snippet:
DesiredCapabilities operaCapabilities = DesiredCapabilities.opera();
operaCapabilities.setCapability("opera.host", "127.0.0.1");
operaCapabilities.setCapability("opera.port", 7001);
operaCapabilities.setCapability("opera.profile", "");
webDriver = new OperaDriver(operaCapabilities);
The above code snippet fails to return a webdriver reference with a SocketTimeoutException Timeout waiting for launcher to connect on port 29392
. I can see that the browser (opera ver. 11.62) is launched with speed dial tab loaded, and the launcher is also executing, but somehow OperaDriver seems to be unable to connect.
The exception I see is:
com.opera.core.systems.runner.OperaRunnerException: Timeout waiting for launcher to connect on port 29392
at com.opera.core.systems.runner.launcher.OperaLauncherRunner.<init>(OperaLauncherRunner.java:159)
at com.opera.core.systems.OperaDriver.<init>(OperaDriver.java:322)
at com.opera.core.systems.OperaDriver.<init>(OperaDriver.java:224)
at com.test.TestMain.main(TestMain.java:31)
Caused by: java.net.SocketTimeoutException: Accept timed out
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
at java.net.ServerSocket.implAccept(ServerSocket.java:462)
at java.net.ServerSocket.accept(ServerSocket.java:430)
at com.opera.core.systems.runner.launcher.OperaLauncherRunner.<init>
(OperaLauncherRunner.java:140)
... 3 more
I have tried -1 for "opera.port" and also 7001, but the capability setting seems to be ignored, since it is attempting to connect with a random port each time. I have my firewalls temporarily turned off as well.
First, let's isolate the exception being hit here:
We learn a few things from this code:
private final int launcherPort =
PortProber.findFreePort()
;
sets ourlauncherPort
, and this variable is uniquely used to establish the connect.Indeed, your configuration of
opera.port
is completely ignored in this block. That seems less than desirable, and it may indeed be a bug or an unexpected regression.Once we establish the local port, a connection attempt is made immediately:
// Setup listener server
ServerSocket listenerServer = new ServerSocket(launcherPort);
listenerServer.setSoTimeout((int) OperaIntervals.LAUNCHER_TIMEOUT.getValue());
// Try to connect
launcherProtocol = new OperaLauncherProtocol(listenerServer.accept());
So, we have a tightly coupled binding to the local server. The port is ignored in favor of a free one on your system, but simultaneously, it should always be able to use that port.
If your firewall is indeed not preventing the connection (as you've discussed), let's assume you desire Opera to be connected to programmatically, instead of manually opening the connection.
According to some documentation,
opera.host
carries the following caveat:(Additional emphasis mine.)
Needless to say, the caveat concerns me. Likewise, despite its apparent inapplicability:
(Additional emphasis mine.)
In short: try running your application as illustrated here:
If this doesn't work, something else is wrong, either with your project or with your current Opera binary, be it version-related or otherwise.