From 3a0f048ac4efd9d9425665b717f6c2fa9ff870ff Mon Sep 17 00:00:00 2001 From: Maxime Noel Date: Tue, 17 Oct 2023 11:12:20 +1300 Subject: [PATCH 1/2] backport catch request_timeout --- .../features/step_definitions/common_steps.rb | 4 +- .../content_lifecycle_steps.rb | 4 +- .../step_definitions/navigation_steps.rb | 44 +++++++++---------- .../features/step_definitions/salt_steps.rb | 4 +- .../features/step_definitions/setup_steps.rb | 2 +- testsuite/features/support/commonlib.rb | 16 +++++++ 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/testsuite/features/step_definitions/common_steps.rb b/testsuite/features/step_definitions/common_steps.rb index be3415596dc8..b94bed2ef784 100644 --- a/testsuite/features/step_definitions/common_steps.rb +++ b/testsuite/features/step_definitions/common_steps.rb @@ -242,10 +242,10 @@ Then(/^I should see the power is "([^"]*)"$/) do |status| within(:xpath, '//*[@for=\'powerStatus\']/..') do repeat_until_timeout(message: "power is not #{status}") do - break if has_content?(status) + break if check_text_and_catch_request_timeout_popup?(status) find(:xpath, '//button[@value="Get status"]').click end - raise "Power status #{status} not found" unless has_content?(status) + raise "Power status #{status} not found" unless check_text_and_catch_request_timeout_popup?(status) end end diff --git a/testsuite/features/step_definitions/content_lifecycle_steps.rb b/testsuite/features/step_definitions/content_lifecycle_steps.rb index 2227b65b4223..3ab32366403c 100644 --- a/testsuite/features/step_definitions/content_lifecycle_steps.rb +++ b/testsuite/features/step_definitions/content_lifecycle_steps.rb @@ -28,7 +28,7 @@ Then(/^I should see a "([^"]*)" text in the environment "([^"]*)"$/) do |text, env| within(:xpath, "//h3[text()='#{env}']/../..") do - raise "Text \"#{text}\" not found" unless has_content?(text) + raise "Text \"#{text}\" not found" unless check_text_and_catch_request_timeout_popup?(text) end end @@ -40,7 +40,7 @@ When(/^I wait until I see "([^"]*)" text in the environment "([^"]*)"$/) do |text, env| within(:xpath, "//h3[text()='#{env}']/../..") do - raise "Text \"#{text}\" not found" unless has_text?(text, wait: DEFAULT_TIMEOUT) + raise "Text \"#{text}\" not found" unless check_text_and_catch_request_timeout_popup?(text, timeout: DEFAULT_TIMEOUT) end end diff --git a/testsuite/features/step_definitions/navigation_steps.rb b/testsuite/features/step_definitions/navigation_steps.rb index f0508eaf8b47..561043af60e6 100644 --- a/testsuite/features/step_definitions/navigation_steps.rb +++ b/testsuite/features/step_definitions/navigation_steps.rb @@ -10,7 +10,7 @@ Then(/^I should see a "(.*)" text in the content area$/) do |text| within('#spacewalk-content') do - raise "Text '#{text}' not found" unless has_content?(text) + raise "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text) end end @@ -37,7 +37,7 @@ end When(/^I wait until I see "([^"]*)" text$/) do |text| - raise "Text '#{text}' not found" unless has_text?(text, wait: DEFAULT_TIMEOUT) + raise "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text, timeout: DEFAULT_TIMEOUT) end When(/^I wait until I do not see "([^"]*)" text$/) do |text| @@ -45,11 +45,11 @@ end When(/^I wait at most (\d+) seconds until I see "([^"]*)" text$/) do |seconds, text| - raise "Text '#{text}' not found" unless has_content?(text, wait: seconds.to_i) + raise "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text, timeout: seconds.to_i) end When(/^I wait until I see "([^"]*)" text or "([^"]*)" text$/) do |text1, text2| - raise "Text '#{text1}' or '#{text2}' not found" unless has_content?(text1, wait: DEFAULT_TIMEOUT) || has_content?(text2, wait: DEFAULT_TIMEOUT) + raise "Text '#{text1}' or '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2, timeout: DEFAULT_TIMEOUT) end When(/^I wait until I see "([^"]*)" (text|regex), refreshing the page$/) do |text, type| @@ -110,7 +110,7 @@ end When(/^I wait until I see the name of "([^"]*)", refreshing the page$/) do |host| - raise 'Overview System page didn\'t load' unless has_content?('Download CSV') || has_content?('Keys') + raise 'Overview System page didn\'t load' unless check_text_and_catch_request_timeout_popup?('Download CSV', text2: 'Keys') system_name = get_system_name(host) step %(I wait until I see the "#{system_name}" system, refreshing the page) end @@ -410,7 +410,7 @@ Given(/^I access the host the first time$/) do visit Capybara.app_host - raise "Text 'Create #{product} Administrator' not found" unless has_content?("Create #{product} Administrator") + raise "Text 'Create #{product} Administrator' not found" unless check_text_and_catch_request_timeout_popup?("Create #{product} Administrator") end # Menu permission check @@ -484,7 +484,7 @@ Then(/^I wait until table row for "([^"]*)" contains "([^"]*)"$/) do |arg1, arg2| xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//*[contains(.,'#{arg1}')]]" within(:xpath, xpath_query) do - raise "xpath: #{xpath_query} has no content #{arg2}" unless has_content?(arg2, wait: DEFAULT_TIMEOUT) + raise "xpath: #{xpath_query} has no content #{arg2}" unless check_text_and_catch_request_timeout_popup?(arg2, timeout: DEFAULT_TIMEOUT) end end @@ -589,7 +589,7 @@ Then(/^I should see "([^"]*)" systems selected for SSM$/) do |arg| within(:xpath, '//span[@id="spacewalk-set-system_list-counter"]') do - raise "There are not #{arg} systems selected" unless has_content?(arg) + raise "There are not #{arg} systems selected" unless check_text_and_catch_request_timeout_popup?(arg) end end @@ -597,26 +597,26 @@ # Test for a text in the whole page # Then(/^I should see a "([^"]*)" text$/) do |text| - raise "Text '#{text}' not found" unless has_content?(text) + raise "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text) end Then(/^I should see a "([^"]*)" text or "([^"]*)" text$/) do |text1, text2| - raise "Text '#{text1}' and '#{text2}' not found" unless has_content?(text1) || has_content?(text2) + raise "Text '#{text1}' and '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2) end Then(/^I should see "([^"]*)" short hostname$/) do |host| system_name = get_system_name(host).partition('.').first - raise "Hostname #{system_name} is not present" unless has_content?(system_name) + raise "Hostname #{system_name} is not present" unless check_text_and_catch_request_timeout_popup?(system_name) end Then(/^I should see "([^"]*)" hostname$/) do |host| system_name = get_system_name(host) - raise "Hostname #{system_name} is not present" unless has_content?(system_name) + raise "Hostname #{system_name} is not present" unless check_text_and_catch_request_timeout_popup?(system_name) end Then(/^I should not see "([^"]*)" hostname$/) do |host| system_name = get_system_name(host) - raise "Hostname #{system_name} is present" if has_content?(system_name) + raise "Hostname #{system_name} is present" if check_text_and_catch_request_timeout_popup?(system_name) end # @@ -624,13 +624,13 @@ # Then(/^I should see "([^"]*)" in the textarea$/) do |text| within('textarea') do - raise "Text '#{text}' not found" unless has_content?(text) + raise "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text) end end Then(/^I should see "([^"]*)" or "([^"]*)" in the textarea$/) do |text1, text2| within('textarea') do - raise "Text '#{text1}' and '#{text2}' not found" unless has_content?(text1) || has_content?(text2) + raise "Text '#{text1}' and '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2) end end @@ -638,7 +638,7 @@ # Test for a text in the whole page using regexp # Then(/^I should see a text like "([^"]*)"$/) do |title| - raise "Regular expression '#{title}' not found" unless has_content?(Regexp.new(title)) + raise "Regular expression '#{title}' not found" unless check_text_and_catch_request_timeout_popup?(Regexp.new(title)) end # @@ -674,19 +674,19 @@ Then(/^I should see a "([^"]*)" text in element "([^"]*)"$/) do |text, element| within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do - raise "Text '#{text}' not found in #{element}" unless has_content?(text) + raise "Text '#{text}' not found in #{element}" unless check_text_and_catch_request_timeout_popup?(text) end end Then(/^I should not see a "([^"]*)" text in element "([^"]*)"$/) do |text, element| within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do - raise "Text '#{text}' found in #{element}" if has_content?(text) + raise "Text '#{text}' found in #{element}" if check_text_and_catch_request_timeout_popup?(text) end end Then(/^I should see a "([^"]*)" or "([^"]*)" text in element "([^"]*)"$/) do |text1, text2, element| within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do - raise "Texts #{text1} and #{text2} not found in #{element}" unless has_content?(text1) || has_content?(text2) + raise "Texts #{text1} and #{text2} not found in #{element}" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2) end end @@ -807,7 +807,7 @@ Then(/^I click on the filter button until page does not contain "([^"]*)" text$/) do |text| repeat_until_timeout(message: "'#{text}' still found") do - break unless has_content?(text) + break unless check_text_and_catch_request_timeout_popup?(text) find('button.spacewalk-button-filter').click has_text?('is filtered', wait: 10) end @@ -815,7 +815,7 @@ Then(/^I click on the filter button until page does contain "([^"]*)" text$/) do |text| repeat_until_timeout(message: "'#{text}' was not found") do - break if has_content?(text) + break if check_text_and_catch_request_timeout_popup?(text) find('button.spacewalk-button-filter').click has_text?('is filtered', wait: 10) end @@ -1156,7 +1156,7 @@ within(:xpath, '//section') do row = find(:xpath, '//div[@class=\'table-responsive\']/table/tbody/tr[.//td]', match: :first) within(row) do - raise "Text '#{system_name}' not found" unless has_text?(system_name) + raise "Text '#{system_name}' not found" unless check_text_and_catch_request_timeout_popup?(system_name) end end end diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 060b5444ff01..6ab7a29e3011 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -194,7 +194,7 @@ Then(/^I should see "([^"]*)" in the command output for "([^"]*)"$/) do |text, host| system_name = get_system_name(host) within("pre[id='#{system_name}-results']") do - raise "Text '#{text}' not found in the results of #{system_name}" unless has_content?(text) + raise "Text '#{text}' not found in the results of #{system_name}" unless check_text_and_catch_request_timeout_popup?(text) end end @@ -405,7 +405,7 @@ def pillar_get(key, minion) salt_call = use_salt_bundle ? 'venv-salt-call' : 'salt-call' output, _code = node.run("#{salt_call} --local key.finger") fing = output.split("\n")[1].strip! - raise "Text: #{fing} not found" unless has_content?(fing) + raise "Text: #{fing} not found" unless check_text_and_catch_request_timeout_popup?(fing) end When(/^I accept "([^"]*)" key$/) do |host| diff --git a/testsuite/features/step_definitions/setup_steps.rb b/testsuite/features/step_definitions/setup_steps.rb index aff4267d9ca3..87235593dece 100644 --- a/testsuite/features/step_definitions/setup_steps.rb +++ b/testsuite/features/step_definitions/setup_steps.rb @@ -100,7 +100,7 @@ When(/^I wait at most (\d+) seconds until the tree item "([^"]+)" contains "([^"]+)" text$/) do |timeout, item, text| within(:xpath, "//span[contains(text(), '#{item}')]/ancestor::div[contains(@class, 'product-details-wrapper')]") do - raise "could not find text #{text} for tree item #{item}" unless has_text?(text, wait: timeout.to_i) + raise "could not find text #{text} for tree item #{item}" unless check_text_and_catch_request_timeout_popup?(text, timeout: timeout.to_i) end end diff --git a/testsuite/features/support/commonlib.rb b/testsuite/features/support/commonlib.rb index 55dcc02d84d7..459c674d6047 100644 --- a/testsuite/features/support/commonlib.rb +++ b/testsuite/features/support/commonlib.rb @@ -120,6 +120,22 @@ def repeat_until_timeout(timeout: DEFAULT_TIMEOUT, retries: nil, message: nil, r raise "Timeout after #{timeout} seconds (Timeout.timeout)#{format_detail(message, last_result, report_result)}" end +def check_text_and_catch_request_timeout_popup?(text1, text2: nil, timeout: Capybara.default_max_wait_time) + start_time = Time.now + repeat_until_timeout(message: "'#{text1}' still not visible", timeout: DEFAULT_TIMEOUT) do + while Time.now - start_time <= timeout + return true if has_text?(text1, wait: 4) + return true if !text2.nil? && has_text?(text2, wait: 4) + next unless has_text?('Request has timed out', wait: 0) + log 'Request timeout found, performing reload' + click_button('reload the page') + start_time = Time.now + raise "Request timeout message still present after #{Capybara.default_max_wait_time} seconds." unless has_no_text?('Request has timed out') + end + return false + end +end + def format_detail(message, last_result, report_result) formatted_message = "#{': ' unless message.nil?}#{message}" formatted_result = "#{', last result was: ' unless last_result.nil?}#{last_result}" if report_result From a113fdb2b5a524b25a7c8f9796abf0b3b93c8a4c Mon Sep 17 00:00:00 2001 From: Maxime Noel Date: Tue, 17 Oct 2023 11:16:07 +1300 Subject: [PATCH 2/2] remove some catch --- testsuite/features/step_definitions/navigation_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/features/step_definitions/navigation_steps.rb b/testsuite/features/step_definitions/navigation_steps.rb index 561043af60e6..b2e82bf27426 100644 --- a/testsuite/features/step_definitions/navigation_steps.rb +++ b/testsuite/features/step_definitions/navigation_steps.rb @@ -110,7 +110,7 @@ end When(/^I wait until I see the name of "([^"]*)", refreshing the page$/) do |host| - raise 'Overview System page didn\'t load' unless check_text_and_catch_request_timeout_popup?('Download CSV', text2: 'Keys') + raise 'Overview System page didn\'t load' unless has_content?('Download CSV') || has_content?('Keys') system_name = get_system_name(host) step %(I wait until I see the "#{system_name}" system, refreshing the page) end @@ -638,7 +638,7 @@ # Test for a text in the whole page using regexp # Then(/^I should see a text like "([^"]*)"$/) do |title| - raise "Regular expression '#{title}' not found" unless check_text_and_catch_request_timeout_popup?(Regexp.new(title)) + raise "Regular expression '#{title}' not found" unless has_content?(Regexp.new(title)) end #