对于我的Rails 3.1应用程序上的Cucumber场景,我使用了@javascript标记,因此激活了Selenium.我收到以下错误:
Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= (Selenium::WebDriver::Error::WebDriverError)
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想使用谷歌浏览器作为浏览器 - 而不是Firefox(我还没有安装).这可能吗?可以做些什么?
事实上,Cucumber/Selenium不应该检测浏览器并使用它吗?
==== ====编辑
添加后
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Run Code Online (Sandbox Code Playgroud)
...到features/support/env.rb,我现在收到此错误:
Unable to find the chromedriver executable. Please download the server from http://code.google.com/p/chromium/downloads/list and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverError)
./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
features/update_memories.feature:11:in `Given I am on the home page'
Run Code Online (Sandbox Code Playgroud)
它在本地运行(未指定driver_path),但不在Heroku上运行.
码:
Selenium::WebDriver::Chrome.driver_path = ENV['GOOGLE_CHROME_SHIM']
browser = Watir::Browser.new :chrome
Run Code Online (Sandbox Code Playgroud)
我在heroku rails控制台中确认了以下值
ENV['GOOGLE_CHROME_BIN'] => "/app/.apt/opt/google/chrome/chrome"
ENV['GOOGLE_CHROME_SHIM'] => "/app/.apt/usr/bin/google-chrome-stable"
Run Code Online (Sandbox Code Playgroud)
已安装的Buildpacks:
https://github.com/heroku/heroku-buildpack-chromedriver
https://github.com/heroku/heroku-buildpack-google-chrome
Run Code Online (Sandbox Code Playgroud)
当前错误:
Selenium :: WebDriver :: Error :: WebDriverError:无法连接到chromedriver 127.0.0.1:9515
搜索unable to connect to chromedriver 127.0.0.1:9515SO返回一堆结果,但没有提到heroku.
我考虑过phantomjs.其他人在这里工作, 使用带有Heroku Rails Unicorn堆栈的无头浏览器
但它被弃用了.在本地运行时出现以下错误.
不赞成使用PhantomJS的Selenium支持.请改用无头Chrome/Firefox或HTMLUnit.
为了透明,我也尝试了以下内容.
更改 browser = Watir::Browser.new :chrome
至 browser = Watir::Browser.new :chrome, headless: true
虽然我没想到这会起作用.
删除:
https://github.com/heroku/heroku-buildpack-chromedriver
添加:
https://github.com/heroku/heroku-buildpack-xvfb-google-chrome.
添加headless宝石.
并运行watirgem页面中给出的以下脚本,http://watir.com/guides/headless/.
require 'watir'
require 'headless'
headless …Run Code Online (Sandbox Code Playgroud)