Class: TestCentricity::ExceptionQueue
- Defined in:
- lib/testcentricity_apps/exception_queue_helper.rb
Instance Attribute Summary collapse
-
#active_ui_element ⇒ Object
Returns the value of attribute active_ui_element.
-
#error_queue ⇒ Object
Returns the value of attribute error_queue.
Class Method Summary collapse
- .disable_enforce_available_locales ⇒ Object
- .enqueue(message) ⇒ Object
- .enqueue_assert_equal(expected, actual, error_message) ⇒ Object
- .enqueue_assert_not_equal(expected, actual, error_message) ⇒ Object
- .enqueue_comparison(ui_object, state, actual, error_msg) ⇒ Object
- .enqueue_exception(error_message) ⇒ Object
- .enqueue_screenshot ⇒ Object
- .post_exceptions(preample_message = nil) ⇒ Object
- .translate(*args, **opts) ⇒ Object
Instance Attribute Details
#active_ui_element ⇒ Object
Returns the value of attribute active_ui_element.
3 4 5 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 3 def active_ui_element @active_ui_element end |
#error_queue ⇒ Object
Returns the value of attribute error_queue.
3 4 5 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 3 def error_queue @error_queue end |
Class Method Details
.disable_enforce_available_locales ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 144 def self.disable_enforce_available_locales saved_enforce_available_locales = I18n.enforce_available_locales I18n.enforce_available_locales = false yield ensure I18n.enforce_available_locales = saved_enforce_available_locales end |
.enqueue(message) ⇒ Object
113 114 115 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 113 def self.enqueue() @error_queue = "#{@error_queue}#{message}\n\n" end |
.enqueue_assert_equal(expected, actual, error_message) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 5 def self.enqueue_assert_equal(expected, actual, ) is_equal = if expected.is_a?(String) && actual.is_a?(String) expected.downcase.strip == actual.downcase.strip else expected == actual end return if is_equal enqueue("#{error_message} to be\n '#{expected}'\nbut found\n '#{actual}'") enqueue_screenshot end |
.enqueue_assert_not_equal(expected, actual, error_message) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 17 def self.enqueue_assert_not_equal(expected, actual, ) return if expected != actual enqueue("#{error_message} to not be equal to '#{expected}'") enqueue_screenshot end |
.enqueue_comparison(ui_object, state, actual, error_msg) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 40 def self.enqueue_comparison(ui_object, state, actual, error_msg) @active_ui_element = ui_object if state.is_a?(Hash) && state.length == 1 state.each do |key, value| case key when :lt, :less_than enqueue_exception("#{error_msg} be less than #{value} but found '#{actual}'") unless actual < value when :lt_eq, :less_than_or_equal enqueue_exception("#{error_msg} be less than or equal to #{value} but found '#{actual}'") unless actual <= value when :gt, :greater_than enqueue_exception("#{error_msg} be greater than #{value} but found '#{actual}'") unless actual > value when :gt_eq, :greater_than_or_equal enqueue_exception("#{error_msg} be greater than or equal to #{value} but found '#{actual}'") unless actual >= value when :starts_with enqueue_exception("#{error_msg} start with '#{value}' but found '#{actual}'") unless actual.start_with?(value) when :ends_with enqueue_exception("#{error_msg} end with '#{value}' but found '#{actual}'") unless actual.end_with?(value) when :contains enqueue_exception("#{error_msg} contain '#{value}' but found '#{actual}'") unless actual.include?(value) when :not_contains, :does_not_contain enqueue_exception("#{error_msg} not contain '#{value}' but found '#{actual}'") if actual.include?(value) when :not_equal enqueue_exception("#{error_msg} not equal '#{value}' but found '#{actual}'") if actual == value when :like, :is_like actual_like = actual.delete("\n") actual_like = actual_like.delete("\r") actual_like = actual_like.delete("\t") actual_like = actual_like.delete(' ') actual_like = actual_like.downcase expected = value.delete("\n") expected = expected.delete("\r") expected = expected.delete("\t") expected = expected.delete(' ') expected = expected.downcase enqueue_exception("#{error_msg} be like '#{value}' but found '#{actual}'") unless actual_like.include?(expected) when :translate expected = translate(value) enqueue_assert_equal(expected, actual, error_msg) when :translate_upcase expected = translate(value) expected = expected.is_a?(Array) ? expected.map(&:upcase) : expected.upcase enqueue_assert_equal(expected, actual, error_msg) when :translate_downcase expected = translate(value) expected = expected.is_a?(Array) ? expected.map(&:downcase) : expected.downcase enqueue_assert_equal(expected, actual, error_msg) when :translate_capitalize expected = translate(value) expected = expected.is_a?(Array) ? expected.map(&:capitalize) : expected.capitalize enqueue_assert_equal(expected, actual, error_msg) when :translate_titlecase expected = translate(value) expected = if expected.is_a?(Array) result = [] expected.each do |item| result.push("#{item.split.each{ |item| item.capitalize! }.join(' ')}") end result else "#{expected.split.each{ |expected| expected.capitalize! }.join(' ')}" end enqueue_assert_equal(expected, actual, error_msg) else raise "#{key} is not a valid comparison key" end end else enqueue_assert_equal(state, actual, error_msg) end end |
.enqueue_exception(error_message) ⇒ Object
24 25 26 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 24 def self.enqueue_exception() enqueue() end |
.enqueue_screenshot ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 117 def self.enqueue_screenshot = Time.now.strftime('%Y%m%d%H%M%S%L') filename = "Screenshot-#{timestamp}.png" path = File.join Dir.pwd, 'reports/screenshots/', filename # take screenshot AppiumConnect.take_screenshot(path) # add screenshot to queue puts "Screenshot saved at #{path}" screen_shot = {path: path, filename: filename} Environ.save_screen_shot(screen_shot) end |
.post_exceptions(preample_message = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 28 def self.post_exceptions( = nil) unless @error_queue.nil? unless .nil? @error_queue = "#{preample_message} - The following errors were found:\n_____________________________\n#{@error_queue}" end raise @error_queue end ensure @error_queue = nil @active_ui_element = nil end |
.translate(*args, **opts) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/testcentricity_apps/exception_queue_helper.rb', line 129 def self.translate(*args, **opts) opts[:locale] ||= I18n.locale opts[:raise] = true I18n.translate(*args, **opts) rescue I18n::MissingTranslationData => err puts err opts[:locale] = :en # fallback to en if the translation is missing. If the translation isn't # in en, then raise again. disable_enforce_available_locales do I18n.translate(*args, **opts) end end |