5
votes

I've been using cucumber + webrat but needed extra Rails 3 compatability and javascript testing so changed to capybara + selenium. Currently I'm on Rails 3.0.7, Cucumber 0.10.2, caybara 1.0.0.beta1.

Problem: When I run a javascript scenario firefox opens "http://www.iana.org/domains/example/" or "www.example.com" instead of my rails app.

I'm sure it's just a small setting I'm missing, but I can't find it and this has had me stumped for a couple days now.

Anyway, my gemfile reads:

group :development, :test do
  gem 'cucumber'
  gem 'cucumber-rails', ">= 0.3.2"
  gem 'pickle'
  gem "launchy"
  gem "rspec-rails"
  gem "Selenium"
  gem "selenium-client"
  gem "selenium-webdriver"
  gem "database_cleaner"
  gem "factory_girl_rails"
  gem "capybara"
  gem "escape_utils"
end

The feature is:

  @wip
  @javascript
  Scenario: Calculate 1 recipe and be deducted a credit
    Given the following page records
      | name | permalink |
      | home | home      |
    And the following role records
      | name       |
      | SuperAdmin |
      | Admin      |
      | Customer   |
    When  I register "adam" with password "password"
    And I go to the index
    Then I should see "5 credits"

The step that opens the firefox window:

    When /^I am logged in as "([^"]*)" with password "([^"]*)"$/ do |username, password|
  unless username.blank?
    visit(root_path)
    fill_in "user_session_username", :with => username
    fill_in "user_session_password", :with => password
    click_button "login"
    page.should have_content("Successfully logged in!")
  end
end

my features/support/env.rb:

   require 'cucumber/rails'
    require 'factory_girl'
    require 'ruby-debug'
    require 'selenium/client'
    # require 'capybara/cucumber' commented out because it doesn't want to work with it in
    Capybara.default_driver = :selenium

    Capybara.server_boot_timeout = 50
    Capybara.default_selector = :css

    begin
      DatabaseCleaner.strategy = :truncation
    rescue NameError
      raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
    end

command prompt says:

    When I register "adam" with password "password"     # features/step_definiti
ons/web_steps.rb:229
      no link with title, id or text 'register' found (Capybara::ElementNotFound
)
      (eval):2:in `click_link'
      ./features/step_definitions/web_steps.rb:232:in `/^I register "([^"]*)" wi
th password "([^"]*)"$/'
      features\credit_behaviour.feature:30:in `When I register "adam" with passw
ord "password"'

I'm fairly new to Rails and to Ruby so be easy on me with any suggestions please, saying that ANY help would be greatly appreciated.

1

1 Answers

14
votes

OK, got it working. Here's what I did.

env.rb added:

require "selenium-webdriver"

and changed my steps with 'visit root_url' to:

visit root_path

I think that's everything I changed.

I honestly thought I'd tried that (and every other permutation of every other issue/fix I've seen). Can't believe I've wasted 3 days on this then found the answer just hours after posting the question publicly.