Selenium不工作与黄瓜/水豚(开箱即用) - MacOSX [英] Selenium doesn't work with Cucumber/Capybara (out of the box) - MacOSX

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

问题描述

我在尝试获取一个黄瓜示例以在硒下运行时遇到问题。我正在运行




  • Rails3

  • Cucumber 0.10.0

  • Capybara 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#场景:用户做x

1场景(1次失败)
12步(跳过12次)
0m0.012s

没有firefox窗口。没有。



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

  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

并运行它:

  bundle exec ruby​​ /tmp/test.rb 

那工作。 Firefox打开窗口并导航到www.stackoverflow.com。



那么如何获得诊断信息来了解黄瓜对水豚做什么?



我正在运行OSX10,Ruby 1.8.7和Firefox 3.6.13。

解决方案

Ok ...我发现了我的问题。在黄瓜碗里的某处是对DatabaseCleaner的依赖,当您使用selenium驱动程序时,它会被触发一次。失败陈述:

  F ______________ F 

告诉我,在安装和拆卸过程中发生了故障。



我发现了这个问题:

p>


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


  2. Add requireruby-debugto env.rb


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





 之前的操作
断点; 0
end





  1. 使用bundle exec运行该功能。


  2. 输入 cat StandardError ,这将告诉调试器在抛出StandardError时断点。 StandardError是Cucumber中所有错误的基类。


  3. 输入 cont ,告诉调试器


将数据库清理器添加为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不工作与黄瓜/水豚(开箱即用) - MacOSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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