Selenium doesn't work with Cucumber/Capybara (out of the box) - MacOSX

安稳与你 提交于 2020-01-21 05:03:21

问题


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.


回答1:


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.




回答2:


Did you try

bundle exec cucumber feature/myfeature.feature

!!



来源:https://stackoverflow.com/questions/4964344/selenium-doesnt-work-with-cucumber-capybara-out-of-the-box-macosx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!