Commit 7bc5598a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents 136ea694 82033e2e
...@@ -9,6 +9,10 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -9,6 +9,10 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
include SharedUser include SharedUser
include WaitForAjax include WaitForAjax
after do
wait_for_ajax if javascript_test?
end
step 'I click link "New Merge Request"' do step 'I click link "New Merge Request"' do
click_link "New Merge Request" click_link "New Merge Request"
end end
......
require Rails.root.join('features/support/wait_for_ajax')
module SharedNote module SharedNote
include Spinach::DSL include Spinach::DSL
include WaitForAjax include WaitForAjax
......
...@@ -15,7 +15,7 @@ if ENV['CI'] ...@@ -15,7 +15,7 @@ if ENV['CI']
Knapsack::Adapters::SpinachAdapter.bind Knapsack::Adapters::SpinachAdapter.bind
end 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) require Rails.root.join('spec', 'support', f)
end end
......
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
...@@ -8,4 +8,8 @@ module WaitForAjax ...@@ -8,4 +8,8 @@ module WaitForAjax
def finished_all_ajax_requests? def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero? page.evaluate_script('jQuery.active').zero?
end end
def javascript_test?
[:selenium, :webkit, :chrome, :poltergeist].include?(Capybara.current_driver)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment