Selenium 不适用于 Cucumber/Capybara(开箱即用)-MacOSX [英] Selenium doesn't work with Cucumber/Capybara (out of the box) - MacOSX

查看:16
本文介绍了Selenium 不适用于 Cucumber/Capybara(开箱即用)-MacOSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试让黄瓜示例在硒下运行时遇到了麻烦.我在跑步

  • Rails3
  • 黄瓜 0.10.0
  • 水豚 0.4.1.2

阅读 https://github.com/jnicklas/capybara 上的文档,看来为了获得一个在 selenium 下运行的示例,我只需要执行以下操作:

第 1 步:使用 @javascript 为场景添加前缀

@javascript场景:用户做了 x...

第 2 步:配置 env.rb 以告诉 capybara 使用哪个驱动程序:

Capybara.javascript_driver = :selenium

当我跑步时:

bundle exec cucumber feature/myfeature.feature

我得到以下信息:

使用默认配置文件...F------------F失败的场景:cucumber features/myfeature.feature:7 # 场景:用户做 x1 个场景(1 个失败)12 步(跳过 12 步)0m0.012s

没有 Firefox 窗口.没有什么.它运行、挂起和死亡.

为了检查 capybara 和 selenium webdriver 是否正常工作,我编写了以下代码:

需要'capybara'需要'水豚/dsl'Capybara.default_driver = :硒类测试包括水豚def dotest访问('http://www.stackoverflow.com')结尾结尾测试.new.dotest

然后使用:

bundle exec ruby​​/tmp/test.rb

这行得通.Firefox 打开窗口并导航到 www.stackoverflow.com.

那么我怎样才能获得诊断信息来了解黄瓜对水豚做了什么?

我正在运行 OSX10.、Ruby 1.8.7 和 Firefox 3.6.13.

解决方案

好的...我发现了我的问题.在黄瓜碗中的某个地方依赖于 DatabaseCleaner,当您使用 selenium 驱动程序时,它会被触发一次.失败声明:

F______________F

告诉我在设置和拆卸过程中发生了故障.Cucumber 没有报告异常,即使使用 -b 它也没有做任何事情.

我是如何发现问题的:

  1. 将 ruby​​-debug 添加为 gem 依赖项

  2. 在 env.rb 中添加 require ruby-debug"

  3. 我在 env.rb 中添加了如下语句:

<块引用>

之前做断点;0结尾

  1. 使用 bundle exec 运行该功能.调试器启动了.

  2. 输入cat StandardError,当StandardError"被抛出时,它将告诉调试器断点.StandardError 是 Cucumber 中所有错误的基类.我们要做的是找出错误在哪里抛出以及为什么.

  3. 输入 cont 告诉调试器继续

添加 database-cleaner 作为 gem 依赖项后,一切都消失了.Firefox 开始启动,事情开始像宣传的那样工作.

I'm having trouble trying to get a cucumber example to run under selenium. I'm running

  • Rails3
  • Cucumber 0.10.0
  • Capybara 0.4.1.2

Reading the doco on https://github.com/jnicklas/capybara, it would appear that all that I need to get an example to run under selenium is to do the following:

Step 1: Prefix the scenario with @javascript

@javascript
Scenario: User does x
...

Step 2: Configure env.rb to tell capybara which driver to use:

Capybara.javascript_driver = :selenium

When I run:

bundle exec cucumber feature/myfeature.feature

I get the following:

Using the default profile...
F------------F

Failing Scenarios:
cucumber features/myfeature.feature:7 # Scenario: User does x

1 scenario (1 failed)
12 steps (12 skipped)
0m0.012s

No firefox window. Nothing. It runs, hangs and dies.

So to check whether capybara and the selenium webdriver is working, I wrote the following code:

require 'capybara'
require 'capybara/dsl'

Capybara.default_driver = :selenium

class Test
   include Capybara
   def dotest
     visit('http://www.stackoverflow.com')
   end
end

Test.new.dotest

And ran it using:

bundle exec ruby /tmp/test.rb

That works. Firefox opens the window and navigates to www.stackoverflow.com.

So how can I get diagnostic information to understand what cucumber is doing to capybara?

I'm running OSX10., Ruby 1.8.7 and Firefox 3.6.13.

解决方案

Ok... I found out my problem. Somewhere in the bowls of cucumber is a dependency on DatabaseCleaner which is being triggered once when you use the selenium driver. The failure statement:

F______________F

Told me that the failure was occurring in the setup and teardown. Cucumber wasn't reporting the exception and even with the -b it didn't do anything.

How I found the problem:

  1. Add ruby-debug as a gem dependency

  2. Add require "ruby-debug" to env.rb

  3. I added the following statement to env.rb:

Before do
    breakpoint; 0
end

  1. Ran the feature using bundle exec. The debugger kicked in.

  2. Type in cat StandardError which will tell the debugger to breakpoint when "StandardError" is thrown. StandardError is the base class for all errors in Cucumber. What we want to do is find out where the error is being thrown and why.

  3. Type in cont to tell the debugger to resume

After adding database-cleaner as a gem dependency, everything went away. Firefox started firing up and things start to work as advertised.

这篇关于Selenium 不适用于 Cucumber/Capybara(开箱即用)-MacOSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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