Commit 87026ee3 authored by Sanad Liaquat's avatar Sanad Liaquat

Refactor select_*_filter methods

Also use refactor retry_on_excpetion and use it in select_*_filter
methods
parent 327eb9a8
......@@ -367,6 +367,7 @@ module QA
end
autoload :Api, 'qa/support/api'
autoload :Waiter, 'qa/support/waiter'
autoload :Retrier, 'qa/support/retrier'
end
end
......
......@@ -39,18 +39,9 @@ module QA
false
end
def retry_on_exception(max_attempts: 3, reload: false, sleep_interval: 0.0)
attempts = 0
begin
def retry_on_exception(max_attempts: 3, reload: false, sleep_interval: 0.5)
QA::Support::Retrier.retry_on_exception(max_attempts: max_attempts, reload_page: (reload && self), sleep_interval: sleep_interval) do
yield
rescue StandardError
sleep sleep_interval
refresh if reload
attempts += 1
retry if attempts < max_attempts
raise
end
end
......@@ -162,6 +153,10 @@ module QA
click_link text
end
def click_body
find('body').click
end
def self.path
raise NotImplementedError
end
......
......@@ -37,18 +37,25 @@ module QA
end
def select_comments_only_filter
click_element :discussion_filter
find_element(:filter_options, "Show comments only").click
select_filter_with_text('Show comments only')
end
def select_history_only_filter
click_element :discussion_filter
find_element(:filter_options, "Show history only").click
select_filter_with_text('Show history only')
end
def select_all_activities_filter
click_element :discussion_filter
find_element(:filter_options, "Show all activity").click
select_filter_with_text('Show all activity')
end
private
def select_filter_with_text(text)
retry_on_exception do
click_body
click_element :discussion_filter
find_element(:filter_options, text).click
end
end
end
end
......
# frozen_string_literal: true
module QA
module Support
module Retrier
module_function
def retry_on_exception(max_attempts: 3, reload_page: nil, sleep_interval: 0.5)
QA::Runtime::Logger.debug("with retry_on_exception: max_attempts #{max_attempts}; sleep_interval #{sleep_interval}")
attempts = 0
begin
QA::Runtime::Logger.debug("Attempt number #{attempts + 1}")
yield
rescue StandardError, RSpec::Expectations::ExpectationNotMetError
sleep sleep_interval
reload_page.refresh if reload_page
attempts += 1
retry if attempts < max_attempts
QA::Runtime::Logger.debug("Raising exception after #{max_attempts} attempts")
raise
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment