问题
I am trying to run Junit tests in parllel ,did a grid setup with 3 nodes , while executing the test got an exception
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
My understanding is There is nothing to do with Firefox and selenium version , I believe the exception is due to lock issued by the firefox for an webdriver instance which is not released within 45000 ms which throws an timeout exception for other webdriver instance trying to connect on port 7055 at the same time (mite be because of system slowness)
So i believe increasing the timeout in this case using the following code
DesiredCapabilities capablities = new DesiredCapabilities();
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.setTimeout(120000);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
capablities = DesiredCapabilities.firefox();
capablities.setCapability("firefox_binary", firefoxBinary);
capablities.setCapability("firefox_profile", profile);
driver = new RemoteWebDriver(new URL("http://" + parameters.getRemoteUrl() + ":4444/wd/hub"), capablities);
but again got an exception WedDriverException : java.util.HashMap cannot be cast to java.lang.String
This exception is thrown when setting capability for firefoxbinary
capablities.setCapability("firefox_binary", firefoxBinary);
Otherwise the RemoteWebdriver instance is created without any issues
Kindly let me know if i am correct in increasing the timeout with regard to the lock on port 7055 , if so kindly help me out in solving the webdriver exception in Firefox Binary
回答1:
I am not sure if the original error(Unable to connect to host 127.0.0.1 on port 7055) you received is due to timeout issue. I am sure it is related to the selenium and firefox version you are using. Take a look at a similar question and my answer on SO if you haven't already. I believe you need to upgrade your selenium version if you are not using the latest.
回答2:
I have the same problem
this code works on my local PC.
FirefoxProfile fp = new FireFoxProfile();
fp.setPreference("Firefox43", "43.0.1");
File pathBinary = new
File("C:\\PathToFirefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
WebDriver driver = new FirefoxDriver(firefoxBinary, fp);
But this code, doesn't ...
FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("Firefox43", "43.0.1");
File pathBinary = new
File("C:\\PathToFirefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
capabilities.setCapability(FirefoxDriver.PROFILE, fp);
capabilities.setCapability(FirefoxDriver.BINARY,firefoxBinary);
WebDriver driver = new RemoteWebDriver(new URL(hubUrl), capabilities);
It seems that there is a bug with RemoteWebDriver, check this question
UPDATE !!!!!
Use :
capabilities.setCapability(FirefoxDriver.BINARY, new
File("C:\\PathToFirefox\\firefox.exe"));
Instead of ...
File pathBinary = new
File("C:\\PathToFirefox\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
capabilities.setCapability(FirefoxDriver.BINARY,firefoxBinary);
来源:https://stackoverflow.com/questions/21260364/weddriverexception-java-util-hashmap-cannot-be-cast-to-java-lang-string-when-i