From f15f9970ab73c1474a45734bd3b792a838b2c4d2 Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Mon, 29 Apr 2019 17:57:34 +1000 Subject: Wait for branches to not be present When testing if branches are deleted, wait for the branch element to not be present. Do the same for both checks (second and third branches). --- qa/qa/page/project/branches/show.rb | 17 +++++++---------- .../repository/add_list_delete_branches_spec.rb | 6 ++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/qa/qa/page/project/branches/show.rb b/qa/qa/page/project/branches/show.rb index 922a6ddb086..ba00ecbd535 100644 --- a/qa/qa/page/project/branches/show.rb +++ b/qa/qa/page/project/branches/show.rb @@ -27,11 +27,9 @@ module QA finished_loading? end - def has_branch_title?(branch_title) + def has_no_branch?(branch_name) within_element(:all_branches) do - within(".item-title") do - has_text?(branch_title) - end + has_no_css?(".js-branch-#{branch_name}") end end @@ -49,13 +47,12 @@ module QA end end - def wait_for_texts_not_to_be_visible(texts) - text_not_visible = wait do - texts.all? do |text| - has_no_text?(text) - end + def wait_for_branch_not_present(branch_name) + branch_not_present = wait(reload: false) do + has_no_branch?(branch_name) end - raise "Expected text(s) #{texts} not to be visible" unless text_not_visible + + raise "Expected branch `#{branch_name}` not to be present" unless branch_not_present end end end diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb index daeee665c93..ac6458385d9 100644 --- a/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb +++ b/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb @@ -72,10 +72,9 @@ module QA Page::Project::Branches::Show.perform do |branches_view| branches_view.delete_branch(third_branch) + branches_view.wait_for_branch_not_present(third_branch) end - expect(page).not_to have_content(third_branch) - Page::Project::Branches::Show.perform(&:delete_merged_branches) expect(page).to have_content( @@ -84,8 +83,7 @@ module QA page.refresh Page::Project::Branches::Show.perform do |branches_view| - branches_view.wait_for_texts_not_to_be_visible([commit_message_of_second_branch]) - expect(branches_view).not_to have_branch_title(second_branch) + branches_view.wait_for_branch_not_present(second_branch) end end end -- cgit v1.2.1 From a5af21cf13869eddf6492c4db727419bf87bb415 Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Wed, 1 May 2019 14:14:01 +1000 Subject: Make max wait time a constant So it can be used elsewhere in the code --- qa/qa/support/waiter.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qa/qa/support/waiter.rb b/qa/qa/support/waiter.rb index 21a399b4a5f..fdcf2d7e157 100644 --- a/qa/qa/support/waiter.rb +++ b/qa/qa/support/waiter.rb @@ -3,9 +3,11 @@ module QA module Support module Waiter + DEFAULT_MAX_WAIT_TIME = 60 + module_function - def wait(max: 60, interval: 0.1) + def wait(max: DEFAULT_MAX_WAIT_TIME, interval: 0.1) QA::Runtime::Logger.debug("with wait: max #{max}; interval #{interval}") start = Time.now -- cgit v1.2.1 From 99a4e97389eb7e9e5a8122a336d7541b46097339 Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Wed, 1 May 2019 14:17:00 +1000 Subject: Check test result via an assertion As long as `has_no_branch?` is only called in an assertion it shouldn't matter if it could return false but still allow the test to continue. So we don't need the new wait method --- qa/qa/page/project/branches/show.rb | 10 +--------- .../3_create/repository/add_list_delete_branches_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/qa/qa/page/project/branches/show.rb b/qa/qa/page/project/branches/show.rb index ba00ecbd535..368e7ac7448 100644 --- a/qa/qa/page/project/branches/show.rb +++ b/qa/qa/page/project/branches/show.rb @@ -29,7 +29,7 @@ module QA def has_no_branch?(branch_name) within_element(:all_branches) do - has_no_css?(".js-branch-#{branch_name}") + has_no_css?(".js-branch-#{branch_name}", wait: Support::Waiter::DEFAULT_MAX_WAIT_TIME) end end @@ -46,14 +46,6 @@ module QA click_element(:delete_merged_branches) end end - - def wait_for_branch_not_present(branch_name) - branch_not_present = wait(reload: false) do - has_no_branch?(branch_name) - end - - raise "Expected branch `#{branch_name}` not to be present" unless branch_not_present - end end end end diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb index ac6458385d9..20793c82d20 100644 --- a/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb +++ b/qa/qa/specs/features/browser_ui/3_create/repository/add_list_delete_branches_spec.rb @@ -72,7 +72,7 @@ module QA Page::Project::Branches::Show.perform do |branches_view| branches_view.delete_branch(third_branch) - branches_view.wait_for_branch_not_present(third_branch) + expect(branches_view).to have_no_branch(third_branch) end Page::Project::Branches::Show.perform(&:delete_merged_branches) @@ -83,7 +83,7 @@ module QA page.refresh Page::Project::Branches::Show.perform do |branches_view| - branches_view.wait_for_branch_not_present(second_branch) + expect(branches_view).to have_no_branch(second_branch) end end end -- cgit v1.2.1 From f00286bc0c5aa01431cc2b337e9db374e68a8395 Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Tue, 7 May 2019 12:43:10 +1000 Subject: Add branch_name qa selector Uses the branch_name element to find a branch with a specific name, instead of using a dynamic CSS class that can't be validated by the sanity selector test --- app/views/projects/branches/_branch.html.haml | 2 +- qa/qa/page/base.rb | 8 ++++---- qa/qa/page/project/branches/show.rb | 3 ++- qa/qa/support/page/logging.rb | 22 +++++++++++++--------- qa/spec/page/logging_spec.rb | 9 ++++++++- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 91c51d5e091..0e15f581ddc 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -10,7 +10,7 @@ .branch-info .branch-title = sprite_icon('fork', size: 12) - = link_to project_tree_path(@project, branch.name), class: 'item-title str-truncated-100 ref-name prepend-left-8' do + = link_to project_tree_path(@project, branch.name), class: 'item-title str-truncated-100 ref-name prepend-left-8 qa-branch-name' do = branch.name - if branch.name == @repository.root_ref %span.badge.badge-primary.prepend-left-5 default diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 9fabf83e2ce..c395e5f6011 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -113,8 +113,8 @@ module QA has_css?(element_selector_css(name), wait: wait, text: text) end - def has_no_element?(name, wait: Capybara.default_max_wait_time) - has_no_css?(element_selector_css(name), wait: wait) + def has_no_element?(name, text: nil, wait: Capybara.default_max_wait_time) + has_no_css?(element_selector_css(name), wait: wait, text: text) end def has_text?(text) @@ -129,8 +129,8 @@ module QA has_no_css?('.fa-spinner', wait: Capybara.default_max_wait_time) end - def within_element(name) - page.within(element_selector_css(name)) do + def within_element(name, text: nil) + page.within(element_selector_css(name), text: text) do yield end end diff --git a/qa/qa/page/project/branches/show.rb b/qa/qa/page/project/branches/show.rb index 368e7ac7448..762eacdab15 100644 --- a/qa/qa/page/project/branches/show.rb +++ b/qa/qa/page/project/branches/show.rb @@ -7,6 +7,7 @@ module QA class Show < Page::Base view 'app/views/projects/branches/_branch.html.haml' do element :remove_btn + element :branch_name end view 'app/views/projects/branches/_panel.html.haml' do element :all_branches @@ -29,7 +30,7 @@ module QA def has_no_branch?(branch_name) within_element(:all_branches) do - has_no_css?(".js-branch-#{branch_name}", wait: Support::Waiter::DEFAULT_MAX_WAIT_TIME) + has_no_element?(:branch_name, text: branch_name, wait: Support::Waiter::DEFAULT_MAX_WAIT_TIME) end end diff --git a/qa/qa/support/page/logging.rb b/qa/qa/support/page/logging.rb index 69b6332ecce..ff505fdbddd 100644 --- a/qa/qa/support/page/logging.rb +++ b/qa/qa/support/page/logging.rb @@ -76,23 +76,18 @@ module QA super end - def has_element?(name, text: nil, wait: Capybara.default_max_wait_time) + def has_element?(name, **kwargs) found = super - msg = ["has_element? :#{name}"] - msg << %Q(with text "#{text}") if text - msg << "(wait: #{wait})" - msg << "returned: #{found}" - - log(msg.compact.join(' ')) + log_has_element_or_not('has_element?', name, found, **kwargs) found end - def has_no_element?(name, wait: Capybara.default_max_wait_time) + def has_no_element?(name, **kwargs) found = super - log("has_no_element? :#{name} returned #{found}") + log_has_element_or_not('has_no_element?', name, found, **kwargs) found end @@ -149,6 +144,15 @@ module QA def log(msg) QA::Runtime::Logger.debug(msg) end + + def log_has_element_or_not(method, name, found, **kwargs) + msg = ["#{method} :#{name}"] + msg << %Q(with text "#{kwargs[:text]}") if kwargs[:text] + msg << "(wait: #{kwargs[:wait] || Capybara.default_max_wait_time})" + msg << "returned: #{found}" + + log(msg.compact.join(' ')) + end end end end diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb index 707a7ff6d98..99e96b81a51 100644 --- a/qa/spec/page/logging_spec.rb +++ b/qa/spec/page/logging_spec.rb @@ -93,7 +93,14 @@ describe QA::Support::Page::Logging do allow(page).to receive(:has_no_css?).and_return(true) expect { subject.has_no_element?(:element) } - .to output(/has_no_element\? :element returned true/).to_stdout_from_any_process + .to output(/has_no_element\? :element \(wait: 2\) returned: true/).to_stdout_from_any_process + end + + it 'logs has_no_element? with text' do + allow(page).to receive(:has_no_css?).and_return(true) + + expect { subject.has_no_element?(:element, text: "more text") } + .to output(/has_no_element\? :element with text \"more text\" \(wait: 2\) returned: true/).to_stdout_from_any_process end it 'logs has_text?' do -- cgit v1.2.1