From 09a7a1f0767285d59855bc3722ed838672c78c7f Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 25 Jan 2018 23:03:14 -0800 Subject: Fix intermittent click error --- qa/qa/page/base.rb | 16 +++++++++------- qa/qa/page/main/login.rb | 6 ++++-- qa/qa/page/project/settings/common.rb | 7 ++++++- 3 files changed, 19 insertions(+), 10 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/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 diff --git a/qa/qa/page/project/settings/common.rb b/qa/qa/page/project/settings/common.rb index c7955124ef3..319cb1045b6 100644 --- a/qa/qa/page/project/settings/common.rb +++ b/qa/qa/page/project/settings/common.rb @@ -17,7 +17,12 @@ module QA def expand_section(name) page.within('#content-body') do page.within('section', text: name) do - click_button 'Expand' unless first('button', text: 'Collapse') + # Because it is possible to click the button before the JS toggle code is bound + wait(reload: false) do + click_button 'Expand' unless first('button', text: 'Collapse') + + page.has_content?('Collapse') + end yield if block_given? end -- cgit v1.2.1