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

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

问题描述

对于我的Rails 3.1应用程序的黄瓜方案,我使用@javascript标签,因此Selenium被激活。
我得到以下错误:

 找不到Firefox二进制文件(os = macosx)。确保Firefox安装或手动设置路径Selenium :: WebDriver :: Firefox :: Binary.path =(Selenium :: WebDriver :: Error :: WebDriverError)

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



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



==== EDIT ====



添加完毕后

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

...到features / support / env.rb,
我现在得到这个错误:

 无法找到chromedriver可执行文件。请从http://code.google.com/p/chromium/downloads/list下载服务器,并将其放在PATH上的某个位置。有关详情,请访问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:在我在主页上

已从此处下载,我试过把chromedriver可执行文件放在/ usr / bin,但我仍然得到上面的错误。



==== EDIT 2 ====

进一步操作并运行sudo chmod + x / usr / bin / chromedriver之后,我现在运行cucumber后出现一个新的错误:

  @javascript 
场景:从主页导航到内存更新页面#features / update_memories.feature:11
给定I在主页#features / step_definitions / web_steps.rb:44
无法连接到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`页'
当我激活存储器的编辑存储器开关我播放#features / step_definitions / memories / memory_steps.rb:5
然后我应该在存储器的编辑存储器页面上播放#features / step_definitions / web_steps.rb:187
PGError:服务器意外关闭连接
这可能意味着服务器在处理请求前或处理请求时异常终止

:ROLLBACK(ActiveRecord :: StatementInvalid)

接近...

解决方案

对于capybara,将其添加到 env.rb

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

下载 Chrome驱动程序可执行文件,并将其复制到你的路径,例如

  $ sudo chmod + x / usr / bin /  chromedriver 


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)

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?

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

====EDIT====

After adding

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

...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'

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

====EDIT 2====

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...

解决方案

For capybara, add this to env.rb

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

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天全站免登陆