Merge branch 'dz-spinach-wait-ajax' into 'master'

Wait for ajax for every merge request spinach test

## What does this MR do?

* removes duplicate `WaitForAjax` module
* ensure we run `wait_for_ajax`after each MR spinach tests

## Why was this MR needed?

Because when visit MR page we do ajax call to check CI status. When testing this page with spinach and JS driver we got random failing tests. It happens because of race condition db cleaner drop data before ajax call finished. So we make sure that every MR spinach scenario with js driver waits for ajax before running next scenario

## What are the relevant issue numbers?

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23461

See merge request !6959
This commit is contained in:
Dmitriy Zaporozhets 2016-10-18 17:53:39 +00:00
commit 7bc5598a72
5 changed files with 9 additions and 14 deletions

View file

@ -9,6 +9,10 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
include SharedUser
include WaitForAjax
after do
wait_for_ajax if javascript_test?
end
step 'I click link "New Merge Request"' do
click_link "New Merge Request"
end

View file

@ -1,5 +1,3 @@
require Rails.root.join('features/support/wait_for_ajax')
module SharedNote
include Spinach::DSL
include WaitForAjax

View file

@ -15,7 +15,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind
end
%w(select2_helper test_env repo_helpers).each do |f|
%w(select2_helper test_env repo_helpers wait_for_ajax).each do |f|
require Rails.root.join('spec', 'support', f)
end

View file

@ -1,11 +0,0 @@
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
end

View file

@ -8,4 +8,8 @@ module WaitForAjax
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
def javascript_test?
[:selenium, :webkit, :chrome, :poltergeist].include?(Capybara.current_driver)
end
end