Class: TestCentricity::AppElements::AppAlert
- Inherits:
-
AppUIElement
- Object
- AppUIElement
- TestCentricity::AppElements::AppAlert
- Defined in:
- lib/testcentricity_apps/app_elements/alert.rb
Instance Attribute Summary
Attributes inherited from AppUIElement
#context, #locator, #mru_app_session, #mru_locator, #mru_object, #mru_parent, #name, #parent, #type
Instance Method Summary collapse
-
#accept ⇒ Object
Performs the action to required accept the currently visible alert modal.
-
#await(seconds) ⇒ Integer
Wait until the alert modal is visible, or until the specified wait time has expired.
- #await_and_respond(action, timeout = 2, button_name = nil) ⇒ Integer
- #buttons ⇒ Object
-
#dismiss ⇒ Object
Performs the action required dismiss the currently visible alert modal.
- #get_caption ⇒ Object
-
#initialize(name, parent, locator, context) ⇒ AppAlert
constructor
A new instance of AppAlert.
Methods inherited from AppUIElement
#clear, #click, #count, #disabled?, #double_tap, #drag_and_drop, #drag_by, #element, #enabled?, #exists?, #get_attribute, #get_locator, #get_name, #get_object_type, #get_value, #height, #hidden?, #hover, #id, #identifier, #long_press, #reset_mru_cache, #scroll_into_view, #selected?, #send_keys, #set, #swipe_gesture, #tap, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x_loc, #y_loc
Constructor Details
#initialize(name, parent, locator, context) ⇒ AppAlert
Returns a new instance of AppAlert.
4 5 6 7 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 4 def initialize(name, parent, locator, context) super @type = :alert end |
Instance Method Details
#accept ⇒ Object
Performs the action to required accept the currently visible alert modal. If the alert modal is still visible after 5 seconds, an exception is raised.
37 38 39 40 41 42 43 44 45 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 37 def accept reset_mru_cache alert_accept wait_until_gone(seconds = 5, post_exception = false) if visible? alert_accept wait_until_gone(5) end end |
#await(seconds) ⇒ Integer
Wait until the alert modal is visible, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Environ.default_max_wait_time. Unlike wait_until_visible or wait_until_exists, this method does not raise an exception if the alert modal does not appear within the specified wait time. Returns true if the alert modal is visible.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 19 def await(seconds) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache visible? end true rescue false end |
#await_and_respond(action, timeout = 2, button_name = nil) ⇒ Integer
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 110 111 112 113 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 73 def await_and_respond(action, timeout = 2, = nil) reset_mru_cache action = action.gsub(/\s+/, '_').downcase.to_sym if action.is_a?(String) if await(timeout) case action when :allow, :accept if .nil? accept elsif Environ.is_ios? Environ.appium_driver.execute_script('mobile: alert', { action: 'accept', buttonLabel: }) else Environ.appium_driver.execute_script('mobile: acceptAlert', { buttonLabel: }) end when :dont_allow, :dismiss if .nil? dismiss elsif Environ.is_ios? Environ.appium_driver.execute_script('mobile: alert', { action: 'dismiss', buttonLabel: }) else Environ.appium_driver.execute_script('mobile: dismissAlert', { buttonLabel: }) end else raise "#{action} is not a valid selector" end if Environ.is_ios? && await(1) case action when :allow, :accept accept when :dont_allow, :dismiss dismiss end if await(1) = Environ.appium_driver.execute_script('mobile: alert', { action: 'getButtons' }) raise "Could not perform #{action} action on active modal. Available modal buttons are #{}" end end true else false end end |
#buttons ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 115 def if Environ.is_ios? Environ.appium_driver.execute_script('mobile: alert', { action: 'getButtons' }) else obj = element object_not_found_exception(obj) = [] labels = obj.find_elements(:class, 'android.widget.Button') labels.each do |label| .push(label.text) end end end |
#dismiss ⇒ Object
Performs the action required dismiss the currently visible alert modal. If the alert modal is still visible after 5 seconds, an exception is raised.
53 54 55 56 57 58 59 60 61 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 53 def dismiss reset_mru_cache alert_dismiss wait_until_gone(seconds = 5, post_exception = false) if visible? alert_dismiss wait_until_gone(5) end end |
#get_caption ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/testcentricity_apps/app_elements/alert.rb', line 130 def obj = element object_not_found_exception(obj) if Environ.is_ios? = [] labels = obj.find_elements(:class, 'XCUIElementTypeStaticText') labels.each do |label| .push(label.text) end else title_obj = obj.find_element(:id, 'android:id/alertTitle') msg_obj = obj.find_element(:id, 'android:id/message') if msg_obj.nil? [title_obj.text] else [title_obj.text, msg_obj.text] end end end |