Skip to content

Commit

Permalink
QE: handle TimeoutError occurring during a page reload
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessOne91 committed Jan 8, 2024
1 parent bc2d962 commit 631c446
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 62 deletions.
10 changes: 2 additions & 8 deletions testsuite/features/step_definitions/common_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
79 changes: 34 additions & 45 deletions testsuite/features/step_definitions/navigation_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions testsuite/features/step_definitions/setup_steps.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion testsuite/features/support/commonlib.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 631c446

Please sign in to comment.