Commit d998f300 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Intermittence adjustments regarding Spinach and Vue

parent 5bd8ed4a
...@@ -48,10 +48,12 @@ Feature: Project Merge Requests ...@@ -48,10 +48,12 @@ Feature: Project Merge Requests
Then I should see "Feature NS-03" in merge requests Then I should see "Feature NS-03" in merge requests
And I should see "Bug NS-04" in merge requests And I should see "Bug NS-04" in merge requests
@javascript
Scenario: I visit an open merge request page Scenario: I visit an open merge request page
Given I click link "Bug NS-04" Given I click link "Bug NS-04"
Then I should see merge request "Bug NS-04" Then I should see merge request "Bug NS-04"
@javascript
Scenario: I visit a merged merge request page Scenario: I visit a merged merge request page
Given project "Shop" have "Feature NS-05" merged merge request Given project "Shop" have "Feature NS-05" merged merge request
And I click link "Merged" And I click link "Merged"
...@@ -180,6 +182,7 @@ Feature: Project Merge Requests ...@@ -180,6 +182,7 @@ Feature: Project Merge Requests
# Markdown # Markdown
@javascript
Scenario: Headers inside the description should have ids generated for them. Scenario: Headers inside the description should have ids generated for them.
When I visit merge request page "Bug NS-04" When I visit merge request page "Bug NS-04"
Then Header "Description header" should have correct id and link Then Header "Description header" should have correct id and link
......
...@@ -32,6 +32,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -32,6 +32,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
expect(page).to have_content @project.path_with_namespace expect(page).to have_content @project.path_with_namespace
expect(page).to have_content @merge_request.source_branch expect(page).to have_content @merge_request.source_branch
expect(page).to have_content @merge_request.target_branch expect(page).to have_content @merge_request.target_branch
wait_for_vue_resource
end end
step 'I fill out a "Merge Request On Forked Project" merge request' do step 'I fill out a "Merge Request On Forked Project" merge request' do
......
...@@ -46,6 +46,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -46,6 +46,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within '.merge-request' do page.within '.merge-request' do
expect(page).to have_content "Wiki Feature" expect(page).to have_content "Wiki Feature"
end end
wait_for_vue_resource
end end
step 'I should see closed merge request "Bug NS-04"' do step 'I should see closed merge request "Bug NS-04"' do
...@@ -56,10 +57,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -56,10 +57,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step 'I should see merge request "Bug NS-04"' do step 'I should see merge request "Bug NS-04"' do
expect(page).to have_content "Bug NS-04" expect(page).to have_content "Bug NS-04"
wait_for_vue_resource
end end
step 'I should see merge request "Feature NS-05"' do step 'I should see merge request "Feature NS-05"' do
expect(page).to have_content "Feature NS-05" expect(page).to have_content "Feature NS-05"
wait_for_vue_resource
end end
step 'I should not see "master" branch' do step 'I should not see "master" branch' do
......
...@@ -24,7 +24,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps ...@@ -24,7 +24,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
# Wait for AJAX requests to complete so they don't blow up if they are # Wait for AJAX requests to complete so they don't blow up if they are
# only handled after `DatabaseCleaner` has already run # only handled after `DatabaseCleaner` has already run
wait_for_ajax wait_for_vue_resource
end end
step 'I should not see the Remove Source Branch button' do step 'I should not see the Remove Source Branch button' do
...@@ -32,7 +32,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps ...@@ -32,7 +32,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
# Wait for AJAX requests to complete so they don't blow up if they are # Wait for AJAX requests to complete so they don't blow up if they are
# only handled after `DatabaseCleaner` has already run # only handled after `DatabaseCleaner` has already run
wait_for_ajax wait_for_vue_resource
end end
step 'There is an open Merge Request' do step 'There is an open Merge Request' do
......
class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
include LoginHelpers include LoginHelpers
include GitlabRoutingHelper include GitlabRoutingHelper
include WaitForVueResource
step 'I click on the revert button' do step 'I click on the revert button' do
find("a[href='#modal-revert-commit']").click find("a[href='#modal-revert-commit']").click
...@@ -15,6 +16,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps ...@@ -15,6 +16,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
step 'I should see the revert merge request notice' do step 'I should see the revert merge request notice' do
page.should have_content('The merge request has been successfully reverted.') page.should have_content('The merge request has been successfully reverted.')
wait_for_vue_resource
end end
step 'I should not see the revert button' do step 'I should not see the revert button' do
......
...@@ -2,6 +2,7 @@ module SharedPaths ...@@ -2,6 +2,7 @@ module SharedPaths
include Spinach::DSL include Spinach::DSL
include RepoHelpers include RepoHelpers
include DashboardHelper include DashboardHelper
include WaitForVueResource
step 'I visit new project page' do step 'I visit new project page' do
visit new_project_path visit new_project_path
...@@ -401,23 +402,28 @@ module SharedPaths ...@@ -401,23 +402,28 @@ module SharedPaths
step 'I visit merge request page "Bug NS-04"' do step 'I visit merge request page "Bug NS-04"' do
visit merge_request_path("Bug NS-04") visit merge_request_path("Bug NS-04")
wait_for_vue_resource
end end
step 'I visit merge request page "Bug NS-05"' do step 'I visit merge request page "Bug NS-05"' do
visit merge_request_path("Bug NS-05") visit merge_request_path("Bug NS-05")
wait_for_vue_resource
end end
step 'I visit merge request page "Bug NS-07"' do step 'I visit merge request page "Bug NS-07"' do
visit merge_request_path("Bug NS-07") visit merge_request_path("Bug NS-07")
wait_for_vue_resource
end end
step 'I visit merge request page "Bug NS-08"' do step 'I visit merge request page "Bug NS-08"' do
visit merge_request_path("Bug NS-08") visit merge_request_path("Bug NS-08")
wait_for_vue_resource
end end
step 'I visit merge request page "Bug CO-01"' do step 'I visit merge request page "Bug CO-01"' do
mr = MergeRequest.find_by(title: "Bug CO-01") mr = MergeRequest.find_by(title: "Bug CO-01")
visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr) visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
wait_for_vue_resource
end end
step 'I visit project "Shop" merge requests page' do step 'I visit project "Shop" merge requests page' do
......
require_relative './wait_for_ajax' require_relative './wait_for_ajax'
require_relative './wait_for_vue_resource'
module WaitForRequests module WaitForRequests
extend self extend self
include WaitForAjax include WaitForAjax
include WaitForVueResource
# This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests # This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests
def wait_for_requests_complete def wait_for_requests_complete
Gitlab::Testing::RequestBlockerMiddleware.block_requests! Gitlab::Testing::RequestBlockerMiddleware.block_requests!
wait_for('pending AJAX requests complete') do wait_for('pending AJAX requests complete') do
Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? &&
finished_all_ajax_requests? finished_all_requests?
end end
ensure ensure
Gitlab::Testing::RequestBlockerMiddleware.allow_requests! Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
end end
def finished_all_requests?
finished_all_ajax_requests? && finished_all_vue_resource_requests?
end
# Waits until the passed block returns true # Waits until the passed block returns true
def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01) def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01)
wait_until = Time.now + max_wait_time.seconds wait_until = Time.now + max_wait_time.seconds
......
...@@ -4,4 +4,14 @@ module WaitForVueResource ...@@ -4,4 +4,14 @@ module WaitForVueResource
loop until page.evaluate_script('window.activeVueResources').zero? loop until page.evaluate_script('window.activeVueResources').zero?
end end
end end
def finished_all_vue_resource_requests?
return true unless javascript_test?
page.evaluate_script('window.activeVueResources || 0').zero?
end
def javascript_test?
Capybara.current_driver == Capybara.javascript_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