typeahead.js test failing on Rails 4 with Cucumber and Capybara-Webkit -


i have following cucumber feature testing input form using typeahead.js:

@javascript scenario: creating battery using typeahead   when create new battery using typeahead   should on show battery page   , should see battery created message 

the test fails on second step following error message:

activerecord::recordnotfound (activerecord::recordnotfound) ./features/step_definitions/admin/car_part_steps/battery_steps.rb:37:in `/^i should on show battery page$/' features/admin/creating_car_parts/creating_batteries.feature:20:in `then should on show battery page' 

the relevant step definitions follows:

when /^i create new battery using typeahead$/   select_from_typeahead :field => 'battery_manufacturer_typeahead',     :select => @manufacturer.name   fill_in 'type', :with => '700w'   click_button 'create battery' end  /^i should on show battery page$/   battery = battery.find_by_type_and_manufacturer_id!('700w', @manufacturer.id)   current_path.should == admin_battery_path(battery)   page.should have_content(battery.type) end 

the select_from_typeahead function follows:

def select_from_typeahead(params)   params[:js_field] ||= params[:field]   params[:select_typeahead] ||= params[:select]   fill_in params[:field], :with => params[:select][0, 2]   page.execute_script "$('##{params[:js_field]}').trigger('focus')"   page.execute_script "$('##{params[:js_field]}').trigger('keydown')"   sleep 0.5   page.execute_script "$('.tt-suggestion:contains(\"#{params[:select_typeahead]}\")').trigger('mouseenter').trigger('click')" end 

the problem appears not have typeahead however, code works in browser, , if add debug output, notice battery gets saved database in first step when running test well, mysteriously disappears before second step runs.

i think it's issue database_cleaner, know doesn't play nice javascript when set use transactions, i've tried setting use truncation instead , disabled transactional fixtures , still doesn't work.

my features/support/env.rb looks this:

require 'simplecov' simplecov.start 'rails'  require 'cucumber/rails'  capybara.default_selector = :css capybara.javascript_driver = :webkit  actioncontroller::base.allow_rescue = false  cucumber::rails::world.use_transactional_fixtures = false databasecleaner.strategy = :truncation  cucumber::rails::database.javascript_strategy = :truncation 

my environment follows:

rails 4.0.2 cucumber 1.3.10 cucumber-rails 1.4.0 capybara 2.2.0 capybara-webkit 1.1.0 database_cleaner 1.2.0 

am missing something, there other way database_cleaner might still interfere test, or else entirely haven't thought of?

any ideas welcome!

i don't think has database cleaner. wouldn't cleanup until end of scenario. debug, highly recommend installing capybara screenshot can see going on in page. provides method screenshot_and_open_image, can use pop open image of browser looks @ exact moment. guesses that:

  1. your jquery isn't doing expect because of timing issues - have tried longer pauses?
  2. your transaction isn't committed. have looked in test.log see if transaction committed?
  3. is form failing validation? try putting screenshot_and_open_image @ beginning of i should on show battery page step see. thing use shared step this, can add screenshots in scenarios debugging:

and /^i take screenshot$/   capybara::screenshot.screenshot_and_open_image end 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -