I recently started seeing this error message when trying to run any Cucumber tests. I've done some research and found a few other similar instances of this error, but most of them were browser related issues. I don't see any browser specific error messages in this output:
unable to bind to locking port 7054 within 45 seconds (Selenium::WebDriver::Error::WebDriverError)
I saw another question posted here that was answered (A selenium webdriver exception), however that solution didn't work for me. Running "lsof -i TCP:7054" does not produce any output.
Just in case anyone suggests this, I have already restarted my machine several times and have wiped my gemset and re-ran "bundle".
Here are the relevant gems I'm using:
capybara (0.4.1.2)
cucumber (0.10.7)
cucumber-rails (0.4.1)
fuubar-cucumber (0.0.9)
selenium-webdriver (0.2.0)
Just to be sure, I've also tried running these tests with Firefox 3.6, 4.0, and 5.0. Same message every time.
Not to be a conspiracy theorist or anything, but everything was working fine before I manually exited running my test 开发者_如何学Gosuite and ran a pkill on all the active Firefox processes that Cucumber started up. I had about 9 Firefox instances running simultaneously during the test suite. I'm not sure if this would have caused something messed up to happen that would produce the results I'm seeing now from running Cucumber tests.
Does anyone have any suggestions for fixing this issue?
Update: Problem Solved
After setting $DEBUG to true and re-running the tests, this error was most interesting:
<Selenium::WebDriver::Firefox::SocketLock:0x00000102f9c010>: getaddrinfo: nodename nor servname provided, or not known
Exception `SocketError' at /Users/bobrossasaurus/.rvm/gems/ruby-1.9.2-p136/gems/selenium-webdriver-0.2.0/lib/selenium/webdriver/common/platform.rb:131 - getaddrinfo: nodename nor servname provided, or not known
After taking a look at platform.rb:131, I noticed that it was attempting to connect to "localhost" on port 80 but was failing. This raised a red flag, as I was recently having trouble accessing "localhost" via browser and instead had to use 127.0.0.1:3000 to view my rails projects.
The Solution:
I was missing the localhost host file entry in /etc/hosts:
127.0.0.1 localhost
Quite an embarrassing issue, but it was the answer nonetheless.
I was able to reset this constant in an initializer with a bit less work. I needed to set it shorter so my script could just create another browser.
# config/initializers/selenium.rb
module Selenium
module WebDriver
module Firefox
class Launcher
Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 10
end
end
end
end
Since this is the top scoring entry on this problem in both google and duck duck go, I'll document my workaround here. The problem as I understand it, is that selenium uses port 7054 as a mutex* to solve the problem that firefox upon start forks the real firefox and quits the starter script. Thus the PID of the real fox can only be guessed from selenium and starting multiple copies of firefox in parallel would lead to constant race conditions. Thus the locking port, which then can become a problem if many firefox need to start in parallel.
Our workaround is to increase this timeout.
# Starting many firefoxen in parallel can easily take more than 45 (default) seconds
module Selenium
module WebDriver
module Firefox
class Launcher
remove_const(:SOCKET_LOCK_TIMEOUT)
end
end
end
end
Selenium::WebDriver::Firefox::Launcher::SOCKET_LOCK_TIMEOUT = 90
in the startup code for selenium.
Fix modeled after this hint: http://www.assertselenium.com/selenium-tips-tricks/
* A mutex is a program object that allows multiple program threads to share the same resource, such as file access, but not simultaneously.
I got the same problem when using Chrome and used the following in my application_system_test_case.rb:
class Selenium::WebDriver::Service
remove_const(:SOCKET_LOCK_TIMEOUT)
SOCKET_LOCK_TIMEOUT = 120
end
精彩评论