Skip to content

Commit ee0ccd2

Browse files
Fix ios[ios/element/alert]
1 parent f439730 commit ee0ccd2

File tree

3 files changed

+9
-116
lines changed

3 files changed

+9
-116
lines changed

ios_tests/lib/ios/specs/ios/element/alert.rb

+7-37
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def nav_once
1111
end
1212

1313
def after_last
14-
ignore { wait(4) { alert_accept } }
14+
alert_accept if exists { s_text('UIActionSheet <title>') }
1515
back_click
1616
screen.must_equal catalog
1717
sleep 1
@@ -23,56 +23,26 @@ def after_last
2323
end
2424

2525
def open_alert
26-
wait_true { s_text('Show OK-Cancel').click; alert_accept_text == 'OK' }
26+
wait_true do
27+
return true if exists { s_text('UIActionSheet <title>') }
28+
s_text('Show OK-Cancel').click
29+
s_text('UIActionSheet <title>').displayed?
30+
end
2731
end
2832

33+
# iOS 7 is not using the alert methods. alert is nil.
2934
def ios7_alert_detected
30-
# iOS 7 doesn't use the standard .alert() method
3135
execute_script 'UIATarget.localTarget().frontMostApp().alert().isNil()'
3236
end
3337

34-
# UIAlertView
35-
t 'alert_click' do
36-
if ios7_alert_detected
37-
# iOS 7 is not using the alert methods anymore so alert_click
38-
# is not possible to implement in a meaningful way
39-
# for this test, we're going to skip testing alert_click on iOS 7
40-
alert_accept
41-
else
42-
alert_click 'OK'
43-
end
44-
end
45-
46-
t 'alert_text' do
47-
if ios7_alert_detected
48-
# iOS 7 is not using the alert methods anymore so alert_text
49-
# is not possible to implement in a meaningful way
50-
# for this test, we're going to skip testing alert_text on iOS 7
51-
alert_accept
52-
else
53-
alert_text.must_equal 'UIAlertView'
54-
alert_accept
55-
end
56-
end
57-
5838
t 'alert_accept' do
5939
alert_accept
6040
end
6141

62-
t 'alert_accept_text' do
63-
alert_accept_text.must_equal 'OK'
64-
alert_accept
65-
end
66-
6742
t 'alert_dismiss' do
6843
alert_dismiss
6944
end
7045

71-
t 'alert_dismiss_text' do
72-
alert_dismiss_text.must_equal 'Cancel'
73-
alert_dismiss
74-
end
75-
7646
t 'after_last' do
7747
after_last
7848
end

ios_tests/lib/run.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def catalog
8282

8383
caps[:app] = ENV['SAUCE_PATH'] if ENV['SAUCE_USERNAME'] && ENV['SAUCE_ACCESS_KEY']
8484

85-
Appium::Driver.new(caps).start_driver
86-
8785
trace_files = []
8886

8987
if one_test
@@ -96,6 +94,7 @@ def catalog
9694
one_test = File.expand_path one_test
9795
end
9896
raise "\nTest #{one_test} does not exist.\n" unless File.exists?(one_test)
97+
Appium::Driver.new(caps).start_driver
9998
# require support (common.rb)
10099
Dir.glob(File.join dir, test_dir + '/*.rb') do |test|
101100
require test
@@ -112,6 +111,7 @@ def catalog
112111
puts " #{File.basename(test, '.*')}"
113112
require test
114113
end
114+
Appium::Driver.new(caps).start_driver
115115
end
116116

117117
trace_files.map! do |f|

lib/appium_lib/ios/element/alert.rb

-77
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
11
# encoding: utf-8
22
module Appium
33
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-
294
# Accept the alert.
305
# @return [void]
316
def alert_accept
@@ -34,64 +9,12 @@ def alert_accept
349
driver.send(:bridge).acceptAlert
3510
end
3611

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-
6312
# Dismiss the alert.
6413
# @return [void]
6514
def alert_dismiss
6615
# @driver.switch_to.alert.dismiss
6716
# ".switch_to.alert" calls getAlertText so use bridge directly
6817
driver.send(:bridge).dismissAlert
6918
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
9619
end # module Ios
9720
end # module Appium

0 commit comments

Comments
 (0)