Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 536
BlueFish Avatar asked Feb 11 '11 00:02

BlueFish


1 Answers

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.

like image 162
BlueFish Avatar answered Oct 14 '22 14:10

BlueFish