lib/appium_lib/ios/element/alert.rb in appium_lib-0.11.1 vs lib/appium_lib/ios/element/alert.rb in appium_lib-0.12.0
- old
+ new
@@ -32,17 +32,33 @@
# ".switch_to.alert" calls getAlertText so use bridge directly
driver.send(:bridge).acceptAlert
end
# Get the text of the alert's accept button.
- # The last button is considered "accept."
+ # The last button is considered "accept." on iOS 6
+ # The first button is considered "accept." on iOS 7
# @return [String]
def alert_accept_text
- a = @driver.find_element(:tag_name, :alert)
- return if a.nil?
- b = a.find_elements(:tag_name, :button)
- b.last.text if b && b.size >= 1
+ old_wait = default_wait
+ set_wait 0
+ target_text = ''
+
+ a = ignore { @driver.find_element(:tag_name, :alert) }
+
+ begin
+ if a.nil? # either no alert or on iOS 7
+ b = xpaths 'actionsheet/button'
+ target_text = b.first.text if b && b.size >= 1
+ else # iOS 6 alert found
+ b = a.find_elements(:tag_name, :button)
+ target_text = b.last.text if b && b.size >= 1
+ end
+ rescue
+ ensure
+ set_wait old_wait
+ return target_text
+ end
end
# Dismiss the alert.
# @return [void]
def alert_dismiss
@@ -50,14 +66,30 @@
# ".switch_to.alert" calls getAlertText so use bridge directly
driver.send(:bridge).dismissAlert
end
# Get the text of the alert's dismiss button.
- # The first button is considered "dismiss."
+ # The first button is considered "dismiss." on iOS 6
+ # The last button is considered "dismiss." on iOS 7
# @return [String]
def alert_dismiss_text
- a = @driver.find_element(:tag_name, :alert)
- return if a.nil?
- b = a.find_elements(:tag_name, :button)
- b.first.text if b && b.size >= 1
+ old_wait = default_wait
+ set_wait 0
+ target_text = ''
+
+ a = ignore { @driver.find_element(:tag_name, :alert) }
+
+ begin
+ if a.nil? # either no alert or on iOS 7
+ b = xpaths 'actionsheet/button'
+ target_text = b.last.text if b && b.size >= 1
+ else # iOS 6 alert found
+ b = a.find_elements(:tag_name, :button)
+ target_text = b.first.text if b && b.size >= 1
+ end
+ rescue
+ ensure
+ set_wait old_wait
+ return target_text
+ end
end
end # module Appium::Ios
\ No newline at end of file