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 ...@@ -367,6 +367,7 @@ module QA
end end
autoload :Api, 'qa/support/api' autoload :Api, 'qa/support/api'
autoload :Waiter, 'qa/support/waiter' autoload :Waiter, 'qa/support/waiter'
autoload :Retrier, 'qa/support/retrier'
end end
end end
......
...@@ -39,18 +39,9 @@ module QA ...@@ -39,18 +39,9 @@ module QA
false false
end end
def retry_on_exception(max_attempts: 3, reload: false, sleep_interval: 0.0) def retry_on_exception(max_attempts: 3, reload: false, sleep_interval: 0.5)
attempts = 0 QA::Support::Retrier.retry_on_exception(max_attempts: max_attempts, reload_page: (reload && self), sleep_interval: sleep_interval) do
begin
yield yield
rescue StandardError
sleep sleep_interval
refresh if reload
attempts += 1
retry if attempts < max_attempts
raise
end end
end end
...@@ -162,6 +153,10 @@ module QA ...@@ -162,6 +153,10 @@ module QA
click_link text click_link text
end end
def click_body
find('body').click
end
def self.path def self.path
raise NotImplementedError raise NotImplementedError
end end
......
...@@ -37,18 +37,25 @@ module QA ...@@ -37,18 +37,25 @@ module QA
end end
def select_comments_only_filter def select_comments_only_filter
click_element :discussion_filter select_filter_with_text('Show comments only')
find_element(:filter_options, "Show comments only").click
end end
def select_history_only_filter def select_history_only_filter
click_element :discussion_filter select_filter_with_text('Show history only')
find_element(:filter_options, "Show history only").click
end end
def select_all_activities_filter def select_all_activities_filter
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 click_element :discussion_filter
find_element(:filter_options, "Show all activity").click find_element(:filter_options, text).click
end
end end
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