System Test with Headless Chrome fails when entire test suite is run

7 views
Skip to first unread message

Jack Royal-Gordon

unread,
Dec 4, 2020, 10:26:24 PM12/4/20
to rs...@googlegroups.com

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) 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.


Reply all
Reply to author
Forward
0 new messages