From a1a458279489e6b95209a55f1878642d53218684 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 25 Jan 2018 23:15:33 -0800 Subject: [PATCH] Fix intermittently failed click in dropdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I haven’t seen `go_to_new_subgroup` fail in the same way, but it seems best to modify it also. --- qa/qa/page/base.rb | 16 +++++++++------- qa/qa/page/group/show.rb | 14 ++++++++++++-- qa/qa/page/main/login.rb | 6 ++++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 81ba80cdbaf..fa7a3760057 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -13,16 +13,18 @@ module QA visit current_url end - def wait(css = '.application', time: 60) - Time.now.tap do |start| - while Time.now - start < time - break if page.has_css?(css, wait: 5) + def wait(max: 60, time: 1, reload: true) + start = Time.now - refresh - end + while Time.now - start < max + return true if yield + + sleep(time) + + refresh if reload end - yield if block_given? + false end def scroll_to(selector, text: nil) diff --git a/qa/qa/page/group/show.rb b/qa/qa/page/group/show.rb index 37ed3b35bce..f23294145dd 100644 --- a/qa/qa/page/group/show.rb +++ b/qa/qa/page/group/show.rb @@ -25,7 +25,12 @@ module QA def go_to_new_subgroup within '.new-project-subgroup' do - find('.dropdown-toggle').click + # May need to click again because it is possible to click the button quicker than the JS is bound + wait(reload: false) do + find('.dropdown-toggle').click + + page.has_css?("li[data-value='new-subgroup']") + end find("li[data-value='new-subgroup']").click end @@ -34,7 +39,12 @@ module QA def go_to_new_project within '.new-project-subgroup' do - find('.dropdown-toggle').click + # May need to click again because it is possible to click the button quicker than the JS is bound + wait(reload: false) do + find('.dropdown-toggle').click + + page.has_css?("li[data-value='new-project']") + end find("li[data-value='new-project']").click end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 9cff2c5c317..95880475ffa 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -10,12 +10,14 @@ module QA view 'app/views/devise/sessions/_new_base.html.haml' do element :login_field, 'text_field :login' - element :passowrd_field, 'password_field :password' + element :password_field, 'password_field :password' element :sign_in_button, 'submit "Sign in"' end def initialize - wait('.application', time: 500) + wait(max: 500) do + page.has_css?('.application') + end end def sign_in_using_credentials