1
1
# encoding: utf-8
2
2
module Appium
3
3
module Ios
4
- # iOS only
5
- # Tap the alert button identified by value.
6
- #
7
- # Click the ok button:
8
- # alert_click 'OK'
9
- #
10
- # Click the first button:
11
- # alert_click 0
12
- #
13
- # @param value [Integer, String] either an integer index of the button or the button's name
14
- # @return [void]
15
- def alert_click value
16
- value = "'#{ value } '" if value . is_a? ( String )
17
- @driver . execute_script "UIATarget.localTarget().frontMostApp().alert().buttons()[#{ value } ].tap();"
18
- end
19
-
20
- # Get the alert message text.
21
- # @return [String]
22
- def alert_text
23
- # this will call get text twice so call bridge directly
24
- # ".switch_to.alert" calls it once, then ".text" another time.
25
- # @driver.switch_to.alert.text
26
- driver . send ( :bridge ) . getAlertText
27
- end
28
-
29
4
# Accept the alert.
30
5
# @return [void]
31
6
def alert_accept
@@ -34,64 +9,12 @@ def alert_accept
34
9
driver . send ( :bridge ) . acceptAlert
35
10
end
36
11
37
- # Get the text of the alert's accept button.
38
- # The last button is considered "accept." on iOS 6
39
- # The first button is considered "accept." on iOS 7
40
- # @return [String]
41
- def alert_accept_text
42
- old_wait = default_wait
43
- set_wait 0
44
- target_text = ''
45
-
46
- a = ignore { @driver . find_element ( :tag_name , :alert ) }
47
-
48
- begin
49
- if a . nil? # either no alert or on iOS 7
50
- b = xpaths 'actionsheet/button'
51
- target_text = b . first . text if b && b . size >= 1
52
- else # iOS 6 alert found
53
- b = a . find_elements ( :tag_name , :button )
54
- target_text = b . last . text if b && b . size >= 1
55
- end
56
- rescue
57
- ensure
58
- set_wait old_wait
59
- return target_text
60
- end
61
- end
62
-
63
12
# Dismiss the alert.
64
13
# @return [void]
65
14
def alert_dismiss
66
15
# @driver.switch_to.alert.dismiss
67
16
# ".switch_to.alert" calls getAlertText so use bridge directly
68
17
driver . send ( :bridge ) . dismissAlert
69
18
end
70
-
71
- # Get the text of the alert's dismiss button.
72
- # The first button is considered "dismiss." on iOS 6
73
- # The last button is considered "dismiss." on iOS 7
74
- # @return [String]
75
- def alert_dismiss_text
76
- old_wait = default_wait
77
- set_wait 0
78
- target_text = ''
79
-
80
- a = ignore { @driver . find_element ( :tag_name , :alert ) }
81
-
82
- begin
83
- if a . nil? # either no alert or on iOS 7
84
- b = xpaths 'actionsheet/button'
85
- target_text = b . last . text if b && b . size >= 1
86
- else # iOS 6 alert found
87
- b = a . find_elements ( :tag_name , :button )
88
- target_text = b . first . text if b && b . size >= 1
89
- end
90
- rescue
91
- ensure
92
- set_wait old_wait
93
- return target_text
94
- end
95
- end
96
19
end # module Ios
97
20
end # module Appium
0 commit comments