Skip to content

Commit 1facf0f

Browse files
authored
add mobile alert (#575)
* add mobile alert * add comment
1 parent a2b0675 commit 1facf0f

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

ios_tests/lib/ios/specs/ios/xcuitest_gestures.rb

+38-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ def after_last
88
screen.must_equal catalog
99
end
1010

11+
def open_alert_ok_cancel
12+
wait_true do
13+
find_element(:name, 'Show OK-Cancel').click
14+
find_element(:name, 'UIActionSheet <title>').displayed?
15+
end
16+
end
17+
18+
def open_alert_custom
19+
wait_true do
20+
find_element(:name, 'Show Customized').click
21+
find_element(:name, 'UIActionSheet <title>').displayed?
22+
end
23+
end
24+
1125
t 'before_first' do
1226
before_first
1327
end
@@ -58,8 +72,31 @@ def after_last
5872
find_element(:name, 'Serena Auroux').displayed?.must_equal true
5973
end
6074

61-
t 'after_last' do
75+
t 'back to top' do
76+
back_click
77+
end
78+
79+
t 'alert' do
80+
wait_true do
81+
UI::Inventory.xcuitest? ? find_element(:name, 'Alerts').click : text('alerts').click
82+
tag(UI::Inventory.navbar).name == 'Alerts' # wait for true
83+
end
84+
85+
open_alert_ok_cancel
86+
alert action: 'accept'
87+
88+
open_alert_ok_cancel
89+
alert action: 'dismiss'
90+
91+
open_alert_custom
92+
alert action: 'accept', button_label: 'Button1'
93+
end
94+
95+
t 'back to top' do
6296
back_click
97+
end
98+
99+
t 'after_last' do
63100
after_last
64101
end
65102
end

lib/appium_lib/ios/xcuitest_gestures.rb

+17
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ def select_picker_wheel(element:, order:, offset: nil)
142142
args[:offset] = offset if offset
143143
execute_script 'mobile: selectPickerWheelValue', args
144144
end
145+
146+
# @param action [String] The following actions are supported: accept, dismiss and getButtons. Mandatory parameter
147+
# @param button_label [String] The label text of an existing alert button to click on.
148+
# This is an optional parameter and is only valid in combination with accept and dismiss actions.
149+
# @return nil or Selenium::WebDriver::Error::NoSuchAlertError if no action sheet or alert
150+
#
151+
# ```ruby
152+
# alert action: "accept"
153+
# alert action: "dismiss"
154+
# ```
155+
def alert(action:, button_label: nil)
156+
return 'Set "accept", "dismiss" or "getButtons" for :action' unless %w(accept dismiss getButtons).include?(action)
157+
158+
args = { action: action }
159+
args[:button_label] if button_label
160+
execute_script 'mobile: alert', args
161+
end
145162
end # module XcuitestGesture
146163
end # module Ios
147164
end # module Appium

0 commit comments

Comments
 (0)