Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cucumber, capybara & selenium works randomly

Setup with cucumber, capybara and selenium but some scenarios works only randomly.
Running
ruby 1.8.6 on rvm
rails 2.3.8
selenium pops open firefox 3.6

I have tried to add this with no luck:

with_scope(selector) do
  click_button(button)
  selenium.wait_for_page_to_load
end

The error output is sometimes:

>  Given I am logged in and have created newsletter and subscribers                           # features/step_definitions/newsletter_send_steps.rb:108
      end of file reached (EOFError)
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:133:in `sysread'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/timeout.rb:62:in `timeout'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/timeout.rb:93:in `timeout'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/protocol.rb:126:in `readline'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:2009:in `read_new'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1050:in `request_without_fakeweb'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1037:in `request_without_fakeweb'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:543:in `start'
      /Users/christianhager/.rvm/rubies/ruby-1.8.6-p399/lib/ruby/1.8/net/http.rb:1035:in `request_without_fakeweb'
      ./features/step_definitions/web_steps.rb:24:in `__instance_exec2'
      ./features/step_definitions/web_steps.rb:9:in `with_scope'
      ./features/step_definitions/web_steps.rb:9:in `with_scope'
      ./features/step_definitions/web_steps.rb:23:in `/^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/'
      features/enhanced/newsletter_send1.feature:7:in `Given I am logged in and have created newsletter and subscribers'

And othertimes:

> no button with value or id or text 'create_user_button' found (Capybara::ElementNotFound)
      ./features/step_definitions/web_steps.rb:24:in `__instance_exec2'
      ./features/step_definitions/web_steps.rb:9:in `with_scope'
      ./features/step_definitions/web_steps.rb:9:in `with_scope'
      ./features/step_definitions/web_steps.rb:23:in `/^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/'
      features/enhanced/newsletter_send1.feature:7:in `Given I am logged in and have created newsletter and subscribers'

And sometimes it just works....

This is how my env.rb looks like

ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation' 
require "selenium-webdriver"

Capybara.default_driver = :selenium
Capybara.default_wait_time = 5 
Capybara.ignore_hidden_elements = false
Capybara.default_selector = :css

ActionController::Base.allow_rescue = false

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation

Before do
 Capybara.reset_sessions!
 DatabaseCleaner.clean
end

Cucumber::Rails::World.use_transactional_fixtures = false

Cucumber-steps:
Given I am on the signup page
And I fill in "user_login" with "[email protected]" within "body"
And I fill in "user_password" with "secret" within "body"
And I fill in "user_password_confirmation" with "secret" within "body"
And I check "terms_of_use" within "body"
And I press "create_user_button" within "body"

Any insight would be great :)

like image 989
Christian Avatar asked Jun 02 '10 12:06

Christian


People also ask

What is cucumber capybara?

cucumber is a BDD tool that expresses testing scenarios in a business-readable, domain-specific language. capybara is an automated testing tool (often used) for ROR applications.

What is Capybara in Ruby?

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.

What is Selenium capybara?

Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.

What is RSpec and capybara?

The tools we'll be using. For this exercise we'll be using RSpec, anecdotally the most popular of the Rails testing frameworks, and Capybara, a library that enables browser interaction (clicking buttons, filling out forms, etc.) using Ruby. You may find some of the RSpec or Capybara syntax confusing or indecipherable.


1 Answers

It's HTTP mocking, if you remove fakeweb or webmock from your environment (entirely), it should all work again.

The last comment by Adam Greene DOES WORK regarding setting up Curb with: Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Curb

Read the thread on the Capybara group.

The problem we're having is playing back recorded http traffic using fakeweb or webmock since web driver is now Curb. So if you're goal was to fake out traffic over Capybara, you'll get browser testing to work again but you won't be able to play the traffic back over the same browser. (We're using VCR to record.)

Adding Curb support is listed as a "ticket" on the Fakeweb's Github Issues site.

like image 59
databyte Avatar answered Sep 19 '22 11:09

databyte