From 7aed23f02d61357c79cc4299a12811e3efbf0cb4 Mon Sep 17 00:00:00 2001 From: Paolo Invernizzi Date: Mon, 8 Jan 2024 14:45:00 +0100 Subject: [PATCH] QE: handle TimeoutError occurring during a page reload --- .../features/step_definitions/common_steps.rb | 10 +-- .../step_definitions/navigation_steps.rb | 79 ++++++++----------- .../features/step_definitions/setup_steps.rb | 10 +-- testsuite/features/support/commonlib.rb | 10 ++- 4 files changed, 47 insertions(+), 62 deletions(-) diff --git a/testsuite/features/step_definitions/common_steps.rb b/testsuite/features/step_definitions/common_steps.rb index 498c4a90251d..fd92004722af 100644 --- a/testsuite/features/step_definitions/common_steps.rb +++ b/testsuite/features/step_definitions/common_steps.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2023 SUSE LLC. +# Copyright (c) 2010-2024 SUSE LLC. # Licensed under the terms of the MIT license. ### This file contains all step definitions concerning general product funtionality @@ -186,13 +186,7 @@ rescue Capybara::ElementNotFound # ignored - pending actions cannot be found end - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored - end + refresh_page end end diff --git a/testsuite/features/step_definitions/navigation_steps.rb b/testsuite/features/step_definitions/navigation_steps.rb index 654877499126..65b73e08bf61 100644 --- a/testsuite/features/step_definitions/navigation_steps.rb +++ b/testsuite/features/step_definitions/navigation_steps.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2010-2023 SUSE LLC. +# Copyright (c) 2010-2024 SUSE LLC. # Licensed under the terms of the MIT license. ### This file contains the definitions for all steps concerning navigation through the Web UI @@ -56,32 +56,32 @@ text = Regexp.new(text) if type == 'regex' next if has_content?(text, wait: 3) - repeat_until_timeout(message: "Couldn't find text '#{text}'") do - break if has_content?(text, wait: 3) + begin + repeat_until_timeout(message: "Couldn't find text '#{text}'") do + break if has_content?(text, wait: 3) - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored + refresh_page end + rescue StandardError => e + # a TimeoutError may be raised while the page still (re)loads, making no screenshot available + find('#page-body', wait: 3) + raise e end end When(/^I wait at most (\d+) seconds until I do not see "([^"]*)" text, refreshing the page$/) do |seconds, text| next if has_no_text?(text, wait: 3) - repeat_until_timeout(message: "I still see text '#{text}'", timeout: seconds.to_i) do - break if has_no_text?(text, wait: 3) + begin + repeat_until_timeout(message: "I still see text '#{text}'", timeout: seconds.to_i) do + break if has_no_text?(text, wait: 3) - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored + refresh_page end + rescue StandardError => e + # a TimeoutError may be raised while the page still (re)loads, making no screenshot available + find('#page-body', wait: 3) + raise e end end @@ -97,22 +97,23 @@ last = Time.now next if has_content?('This action\'s status is: Completed.', wait: 3) - repeat_until_timeout(timeout: timeout.to_i, message: 'Event not yet completed') do - break if has_content?('This action\'s status is: Completed.', wait: 3) - raise SystemCallError, 'Event failed' if has_content?('This action\'s status is: Failed.', wait: 3) - - current = Time.now - if current - last > 150 - log "#{current} Still waiting for action to complete..." - last = current - end - begin - accept_prompt do - execute_script 'window.location.reload()' + begin + repeat_until_timeout(timeout: timeout.to_i, message: 'Event not yet completed') do + break if has_content?('This action\'s status is: Completed.', wait: 3) + raise SystemCallError, 'Event failed' if has_content?('This action\'s status is: Failed.', wait: 3) + + current = Time.now + if current - last > 150 + log "#{current} Still waiting for action to complete..." + last = current end - rescue Capybara::ModalNotFound - # ignored + + refresh_page end + rescue StandardError => e + # a TimeoutError may be raised while the page still (re)loads, making no screenshot available + find('#page-body', wait: 3) + raise e end end @@ -136,13 +137,7 @@ repeat_until_timeout(message: "Text '#{text}' is still visible") do break unless has_content?(text, wait: 3) - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored - end + refresh_page end end @@ -157,13 +152,7 @@ # If the connection failed try reloading since the VM may not have been ready if find(:xpath, '//*[contains(@class, "modal-title") and text() = "Failed to connect"]') - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored - end + refresh_page end end end diff --git a/testsuite/features/step_definitions/setup_steps.rb b/testsuite/features/step_definitions/setup_steps.rb index 8127d959d96d..d3380120427e 100644 --- a/testsuite/features/step_definitions/setup_steps.rb +++ b/testsuite/features/step_definitions/setup_steps.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2023 SUSE LLC. +# Copyright (c) 2024 SUSE LLC. # Licensed under the terms of the MIT license. ### This file contains all steps concerning setting up a test environment. @@ -396,13 +396,7 @@ repeat_until_timeout(message: "Couldn't find checked radio button #{arg1}") do break if has_checked_field?(arg1) - begin - accept_prompt do - execute_script 'window.location.reload()' - end - rescue Capybara::ModalNotFound - # ignored - end + refresh_page end end end diff --git a/testsuite/features/support/commonlib.rb b/testsuite/features/support/commonlib.rb index 7dac283396ec..4d1c95cb63bb 100644 --- a/testsuite/features/support/commonlib.rb +++ b/testsuite/features/support/commonlib.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2013-2023 SUSE LLC. +# Copyright (c) 2013-2024 SUSE LLC. # Licensed under the terms of the MIT license. require 'tempfile' @@ -122,6 +122,14 @@ def format_detail(message, last_result, report_result) "#{formatted_message}#{formatted_result}" end +def refresh_page + accept_prompt do + execute_script 'window.location.reload()' + end +rescue Capybara::ModalNotFound + # ignored +end + def click_button_and_wait(locator = nil, **options) click_button(locator, options) begin