I’ve got a system test that runs with headless Chrome (it’s the only system 
test I’ve written so far) that runs fine on it’s own, but when run as part of 
the entire test suite gives the following error:

Failure/Error: check 'send_amazon_email_after_processing'   # turns it on
     
     Capybara::ElementNotFound:
       Unable to find checkbox "send_amazon_email_after_processing"
     
     [Screenshot]: 
tmp/screenshots/failures_r_spec_example_groups_upload_features_amazon_toggle_send_email_flag_turns_off_the_flag_723.png

Here is the test:

require 'spec_helper'
require 'wait_for_ajax'

describe "Upload Features", js: true do
  describe 'Amazon' do
    describe 'Toggle "Send Email" flag' do
      before do
        @user = FactoryBot.create :user
        FactoryBot.create :user_distributor, :amazon, user: @user
        integration_sign_in(@user)
        visit uploads_path
        expect(page.title).to include 'Upload'
        wait_for_page_load
      end
      
      it 'defaults to off' do
        expect(page).to have_unchecked_field 
'send_amazon_email_after_processing'
      end
      
    end
  end
end

The code in “wait_for_ajax”, which includes “wiat_for_page_load”, is:

module WaitForAjax
  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
  
  def wait_for_page_load(css='div#body')
    expect(page).to have_css(css)
  end
end

RSpec.configure do |config|
  config.include WaitForAjax, type: :system
end

The “wait_for_page_load” uses the method described here 
(https://stackoverflow.com/questions/42891801/netreadtimeout-netreadtimeout-and-seleniumwebdrivererrorunknownerror
 
<https://stackoverflow.com/questions/42891801/netreadtimeout-netreadtimeout-and-seleniumwebdrivererrorunknownerror>)
 for waiting for the page to load. And it works fine when I run the file by 
itself (e.g. “rspec ./spec/system/uploads_system_spec.rb”, but not when the 
entire suite is run “rspec”). When I look at the screen shot, I see a blank 
page with only the page header, but no other content. This is exactly what I 
saw when running the test standalone until I added the call to 
#wait_for_page_load.


-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/EE9FF6CF-2B64-4F4C-9463-1FF7DB108B58%40pobox.com.

Reply via email to