Class: TestCentricity::AppAlert
- Inherits:
-
AppUIElement
- Object
- AppUIElement
- TestCentricity::AppAlert
- Defined in:
- lib/testcentricity/app_elements/alert.rb
Instance Attribute Summary
Attributes inherited from AppUIElement
#context, #locator, #name, #parent, #type
Instance Method Summary collapse
-
#accept ⇒ Object
Performs the action 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
-
#dismiss ⇒ Object
Performs the action required dismiss the currently visible alert modal.
-
#initialize(name, parent, locator, context) ⇒ AppAlert
constructor
A new instance of AppAlert.
Methods inherited from AppUIElement
#clear, #click, #disabled?, #double_tap, #enabled?, #exists?, #get_attribute, #get_caption, #get_locator, #get_name, #get_object_type, #get_value, #height, #hidden?, #scroll, #selected?, #send_keys, #set, #swipe, #tag_name, #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.
3 4 5 6 |
# File 'lib/testcentricity/app_elements/alert.rb', line 3 def initialize(name, parent, locator, context) super @type = :alert end |
Instance Method Details
#accept ⇒ Object
Performs the action required accept the currently visible alert modal. If the alert modal is still visible after 5 seconds, an exception is raised.
33 34 35 36 |
# File 'lib/testcentricity/app_elements/alert.rb', line 33 def accept alert_accept wait_until_gone(5) 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.
18 19 20 21 22 23 24 25 |
# File 'lib/testcentricity/app_elements/alert.rb', line 18 def await(seconds) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { exists? } true rescue false end |
#await_and_respond(action, timeout = 2, button_name = nil) ⇒ Integer
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 |
# File 'lib/testcentricity/app_elements/alert.rb', line 59 def await_and_respond(action, timeout = 2, = nil) if await(timeout) case action when :allow, :accept if .nil? accept elsif Environ.is_ios? $driver.execute_script('mobile: alert', { action: 'accept', buttonLabel: }) else $driver.execute_script('mobile: acceptAlert', { buttonLabel: }) end when :dont_allow, :dismiss if .nil? dismiss elsif Environ.is_ios? $driver.execute_script('mobile: alert', { action: 'dismiss', buttonLabel: }) else $driver.execute_script('mobile: dismissAlert', { buttonLabel: }) end else raise "#{action} is not a valid selector" end if Environ.is_ios? && await(1) = $driver.execute_script('mobile: alert', { action: 'getButtons' }) raise "Could not perform #{action} action on active modal. Available modal buttons are #{}" end true else false 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.
44 45 46 47 |
# File 'lib/testcentricity/app_elements/alert.rb', line 44 def dismiss alert_dismiss wait_until_gone(5) end |