可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
While testing scenario by cucumber
i'm getting the following error when running rspec
tests
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
Using ruby (1.9.2)
selenium-webdriver (2.27.2)
and firefox (19.0)
Using rspec-rails (2.12.1)
, capybara (2.0.2)
and several other gems, Also i have added launchy
gem but they don't seem to be a problem. And i am using Windows 7
.
回答1:
I had the same problem (on Linux). Fixed with:
gem update selenium-webdriver
Now I am using ruby 1.9.3-p286, selenium-webdriver 2.29.0, firefox 18.0
As well as rspec-rails 2.9.0, capybara 1.1.2, and capybara-webkit 0.12.1
I added selenium-webdriver 2.29.0 to my Gemfile to be safe.
回答2:
It seems Selenium Webdriver gets frequent updates to keep up with Firefox. But how do you know which version you need? Hopefully this procedure will work even as versions change:
Go to http://www.seleniumhq.org/download/.
Scroll down to Selenium Client & WebDriver Language Bindings.
In that section, in the Ruby language line, click on "Change Log" (direct link).
In the Change Log, determine which version of Selenium you need for your version of Firefox.
If you're using Bundler, run bundle show selenium-webdriver
to see which version you have. To update, for example to 2.35.0, add this line to your Gemfile
:
gem 'selenium-webdriver', '2.35.0'
and then run bundle update
to install. If you are using Spork, remember to re-start it before re-running your tests.
Update
One StackOverflow answer indicates that the Change Log may be updated sooner in the source code repository than at seleniumhq.org. The repository Change Log for Ruby is here: https://github.com/SeleniumHQ/selenium/blob/master/rb/CHANGES.
Downgrading Firefox
If you need to downgrade Firefox on Ubuntu 12.04, this answer explains how to go back to Firefox 20. A more general description of a way to switch to any version of Firefox is given here. Then use this answer to put Firefox updates on hold until Selenium releases an update that works with the later version of Firefox.
In my case, I downgraded Firefox only to discover that Selenium Webdriver had recently been updated to handle the latest version, so check for Selenium updates first!
回答3:
bundle update selenium-webdriver
回答4:
Just ran into this on the CI server and found that it was because Firefox had no display to use. I had thought that selenium webdriver would make it work with no further intervention but this was not the case.
Adding Xvfb into the mix made it work.
For Rails running Cucumber features:
gem 'headless'
then in features/support/env.rb
Before do
if Capybara.current_driver == :selenium
require 'headless'
headless = Headless.new
headless.start
end
end
回答5:
This error happens when selenium and firefox versions are incompatible.
There are two options.
Update selenium:
gem update selenium-webdriver
If it still fails, then selenium hasn't been updated to the newest version.
Downgrade the version of firefox:
sudo apt-get purge firefox
To see the available packages for download
apt-cache showpkg firefox
sudo apt-get install firefox=#older_version#
回答6:
The magic combination that worked for me was Firefox 19.0 and selenium web-driver 2.32.1 (latest at the time of writing). Firefox 20.x and 21.x did not work. I had to downgrade Firefox. Also keep in mind that (at least on Mac OS), if you go to FireFox Menu -> About Firefox, it will automatically upgrade to the latest release. Don't do that.
回答7:
If the above does now work, like in my case, give this a shot.
I was getting the time out error on one machine and not another. Both machines are thin clients running the exact same versions of everything. So that ruled out incompatible firefox versions (error occured on one machine and not the other)
Turned out that there was an issue with the port that headless was using. There was another process using that port.
The below fixed the issue for me:
Add the following line in the .zshenv file
export XVFB_DISPLAY='new-port-number'
then run command zsh
in terminal to set change
回答8:
I had this issue when I was starting irb from a terminal where I had su ed my self to another user. I would get this error when I ran irb as that user. But not if I ran as root. And not when I exited back out to a shell owned by the logged in user.
回答9:
For me, I had already updated the gems but then needed to update my bundle.
In powershell, navigate to your directory then update the bundle:
cd D:\Projects\LazyAutomation
bundle update
回答10:
for anyone using Vagrant, if you log in enabling XServer firefox can start correctly which solved it for me. vagrant ssh -- -X
回答11:
Downgrade Firefox.
If already using gem 'headless'
and updating gems is not desirable as for right now, then you need to downgrade firefox.
For Ubuntu (but other linux distros would be pretty similar) you should:
Remove firefox that comes with Ubuntu latest versions
sudo apt-get purge firefox
You can complement with removing some associated data as explained here
Now, install an older version of Firefox. For me, version 42.0
worked (as our Travis.ci uses it)
$ export FIREFOX_SOURCE_URL='https://download.mozilla.org/?product=firefox-42.0&lang=en-US&os=linux64'
$ wget --no-verbose -O /tmp/firefox-42.0.tar.bz2 $FIREFOX_SOURCE_URL
$ tar xvC ~/. -f /tmp/firefox-42.0.tar.bz2
ln -s ~/firefox/firefox ~/bin/firefox
Open a new terminal tab and run your cucumber specs/selenium specs.
You can now download the newest version of Firefox and create a .desktop
file in /usr/share/applications/
to access it from the dock. And let Selenium find by default the older version. Take this for reference
回答12:
After following ballPointPenguin's suggestion, I can now use watir-webdriver to retrieve local files, or files in my local apache install's htdocs directory, or files on the web:
1) file:///Users/me/jquery_programs/1.htm
2) 'http://localhost:8080/my.html'
3) 'http://www.google.com'
require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto 'http://localhost:8080/my.html'
Before updating, I was getting the error:
`connect_until_stable': unable to obtain stable firefox connection in
60 seconds (127.0.0.1:7055)
(Selenium::WebDriver::Error::WebDriverError)