1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Capybara tests - alternative to sleep

Discussion in 'Ruby' started by clem_c_rock, Sep 29, 2016.

  1. #1
    I’ve been trying to find alternatives to using sleep for some time and it seems that every single suggested method to avoid using sleep never works and I’m at the end of my rope.


    
    
     it 'finds the correct product when searching by job type', js: true do
    
     fill_in('filterrific_for_work_type', with: 'Central')
    
     # once again, sleep feels like the only thing that works
    
     #sleep 1 # TODO: find a better way..
    
     expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
    
     expect(page).to have_link('IP Central Report',
    
     href: work_queue_item_path(@release.id))
    
     end
    
    
    Code (markup):

    I also have this wait for ajax helper:


    
    
    module CapybaraHelpers
    
     def wait_for_ajax
    
     Timeout.timeout(Capybara.default_max_wait_time) do
    
     loop until finished_all_ajax_requests?
    
     end
    
     end
    
    
     def finished_all_ajax_requests?
    
     page.evaluate_script('jQuery.active').zero?
    
     end
    
    end
    
    
    Code (markup):

    And in spec_helper.rb:


    
    
    RSpec.configure do |config|
    
    config.include CapybaraHelpers, type: :feature
    
    End
    
    
    Code (markup):

    This test breaks unless I add the sleep 1. and I’ve tried so many iterations using things like ‘within’ ‘find’, ‘have_content’ ect. This is really driving me crazy.
     
    clem_c_rock, Sep 29, 2016 IP