黄瓜;Selenium WebDriver - 如何使用 Google Chrome 作为测试浏览器而不是 Firefox [英] Cucumber; Selenium WebDriver - how to use Google Chrome as the testing browser instead of Firefox

查看:24
本文介绍了黄瓜;Selenium WebDriver - 如何使用 Google Chrome 作为测试浏览器而不是 Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的 Rails 3.1 应用程序上的 Cucumber 场景,我使用了@javascript 标签,因此 Selenium 被激活.我收到以下错误:

For a Cucumber scenario on my Rails 3.1 app, I used the @javascript tag, so Selenium is activated. I get the following error:

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)

如果可能,我想使用 Google Chrome 作为浏览器 - 而不是 Firefox(我还没有安装).这可能吗?可以做什么?

If possible, I'd like to use Google Chrome as the browser - not Firefox (which I haven't installed). Is this possible? What could be done?

实际上,Cucumber/Selenium 不应该检测浏览器并使用它吗?

In fact, shouldn't Cucumber/Selenium detect a browser and use it?

====编辑====

添加后

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

...到 features/support/env.rb,我现在收到此错误:

...to features/support/env.rb, I now get this error:

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'

我从 这里下载,我已经尝试将 chromedriver 可执行文件放在/usr/bin 中,但仍然出现上述错误.

I've downloaded from here, and I've tried putting the chromedriver executable in /usr/bin, but I still get the above error.

====编辑 2====

====EDIT 2====

在更进一步并按照下面的建议运行sudo chmod +x/usr/bin/chromedriver"后,我现在在运行 cucumber 后得到一个新错误:

After going one step further and running "sudo chmod +x /usr/bin/chromedriver" as suggested below, I now get a new error after running cucumber:

@javascript
  Scenario: navigate to memory update page from home page              # features/update_memories.feature:11
    Given I am on the home page                                        # features/step_definitions/web_steps.rb:44
      unable to connect to chromedriver http://127.0.0.1:57870 (Selenium::WebDriver::Error::WebDriverError)
      ./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
      features/update_memories.feature:12:in `Given I am on the home page'
    When I activate the edit memory switch for the memory "I played"   # features/step_definitions/memories/memory_steps.rb:5
    Then I should be on the edit memory page for the memory "I played" # features/step_definitions/web_steps.rb:187
      PGError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
      : ROLLBACK (ActiveRecord::StatementInvalid)

帮助表示赞赏!越来越近了……

Help appreciated! Getting closer...

推荐答案

对于水豚,将这个添加到 env.rb

For capybara, add this to env.rb

Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :chrome)
end

下载 Chrome 驱动程序可执行文件并将其复制到您的路径中,例如/usr/bin/ 并使其可执行

Download the Chrome driver executable and copy it in you path, e.g. /usr/bin/ and make it executable

$ sudo chmod +x /usr/bin/chromedriver

这篇关于黄瓜;Selenium WebDriver - 如何使用 Google Chrome 作为测试浏览器而不是 Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆