Skip to content

Commit cfabca1

Browse files
montdidierKazuCocoa
authored andcommitted
Feature/xcuitest (#388)
* swipe proffers use of delta_x, delta_y instead of end_x, end_y which are marked as deprecated * stylistic compliance * support for xcuitest backend driver * cleaned up dependencies a little * fixes for page command * fix rubocop offences * first passsupport both XCUITest and UIAutomation automationName * some xpath query fixes * fix more rubocop offences * rspec tests can target UIAutomation and XCUITest backends * rubocop fix * replace uiautomation SearchContext * XCUITest => xcuitest * use downcase to ensure XCUITest => ucuitest
1 parent 75dd133 commit cfabca1

19 files changed

+314
-179
lines changed

appium_lib.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
1818
s.add_runtime_dependency 'awesome_print', '~> 1.6'
1919
s.add_runtime_dependency 'json', '~> 1.8'
2020
s.add_runtime_dependency 'tomlrb', '~> 1.1'
21-
s.add_runtime_dependency 'nokogiri', '~> 1.6.6'
21+
s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.6'
2222

2323
s.add_development_dependency 'posix-spawn', '~> 0.3'
2424
s.add_development_dependency 'hashdiff', '~> 0.2.2'
25-
s.add_development_dependency 'spec', '~> 5.3.4'
25+
s.add_development_dependency 'spec', '~> 5.3', '>= 5.3.4'
2626
s.add_development_dependency 'fakefs', '~> 0.6.7'
2727

2828
s.add_development_dependency 'rake', '~> 10.4'

ios_tests/Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
source 'https://rubygems.org'
22
gemspec path: File.expand_path('../../', __FILE__) # __dir__ fails on 1.9
3+
4+
gem 'appium_console'

ios_tests/appium.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[caps]
22
platformName = "ios"
3-
platformVersion = "9.3"
3+
platformVersion = "10.1"
44
deviceName ="iPhone Simulator"
5+
automationName = 'xcuitest'
56
app = "./UICatalog.app"
67

78
[appium_lib]

ios_tests/lib/common.rb

+100
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,103 @@ def screen
3232
def catalog
3333
'UICatalog'
3434
end
35+
36+
module UI
37+
module Inventory
38+
private
39+
40+
def self.xcuitest?
41+
$driver.automation_name && $driver.automation_name == 'xcuitest'
42+
end
43+
44+
public
45+
46+
def self.navbar
47+
if xcuitest?
48+
'XCUIElementTypeNavigationBar'
49+
else
50+
'UIANavigationBar'
51+
end
52+
end
53+
54+
def self.button
55+
if xcuitest?
56+
'XCUIElementTypeButton'
57+
else
58+
'UIAButton'
59+
end
60+
end
61+
62+
def self.static_text
63+
if xcuitest?
64+
'XCUIElementTypeStaticText'
65+
else
66+
'UIAStaticText'
67+
end
68+
end
69+
70+
def self.text_field
71+
if xcuitest?
72+
'XCUIElementTypeTextField'
73+
else
74+
'UIATextField'
75+
end
76+
end
77+
78+
def self.secure_text_field
79+
if xcuitest?
80+
'XCUIElementTypeSecureTextField'
81+
else
82+
'UIASecureTextField'
83+
end
84+
end
85+
86+
def self.picker
87+
if xcuitest?
88+
'XCUIElementTypePicker'
89+
else
90+
'UIAPicker'
91+
end
92+
end
93+
94+
def self.action_sheet
95+
if xcuitest?
96+
'XCUIElementTypeActionSheet'
97+
else
98+
'UIActionSheet'
99+
end
100+
end
101+
102+
def self.table
103+
if xcuitest?
104+
'XCUIElementTypeTable'
105+
else
106+
'UIATable'
107+
end
108+
end
109+
110+
def self.table_cell
111+
if xcuitest?
112+
'XCUIElementTypeCell'
113+
else
114+
'UIATableCell'
115+
end
116+
end
117+
118+
def self.other
119+
if xcuitest?
120+
'XCUIElementTypeOther'
121+
else
122+
fail 'unknown UIA element: other'
123+
end
124+
end
125+
126+
def self.status_bar
127+
if xcuitest?
128+
'XCUIElementTypeStatusBar'
129+
else
130+
'UIAStatusBar'
131+
end
132+
end
133+
end
134+
end

ios_tests/lib/ios/specs/common/helper.rb

+21-25
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ def before_first
7070

7171
t 'back' do
7272
# start page
73-
tag('UIANavigationBar').name.must_equal 'UICatalog'
73+
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
7474
# nav to new page.
7575
wait_true do
7676
text('buttons').click
77-
tag('UIANavigationBar').name == 'Buttons'
77+
tag(UI::Inventory.navbar).name == 'Buttons'
7878
end
7979

80-
tag('UIANavigationBar').name.must_equal 'Buttons'
80+
tag(UI::Inventory.navbar).name.must_equal 'Buttons'
8181
# go back
8282
back_click
8383
# start page
84-
tag('UIANavigationBar').name.must_equal 'UICatalog'
84+
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
8585
end
8686

8787
t 'session_id' do
@@ -90,25 +90,25 @@ def before_first
9090
end
9191

9292
t 'xpath' do
93-
xpath('//UIAStaticText').name.must_equal 'UICatalog'
93+
xpath("//#{UI::Inventory.static_text}").name.must_equal 'UICatalog'
9494
end
9595

9696
t 'xpaths' do
97-
xpaths('//UIAStaticText').length.must_equal 25
97+
xpaths("//#{UI::Inventory.static_text}").length.must_equal 25
9898
end
9999

100100
def uibutton_text
101101
'Buttons'
102102
end
103103

104104
t 'ele_index' do
105-
ele_index('UIAStaticText', 2).name.must_equal uibutton_text
105+
ele_index(UI::Inventory.static_text, 2).name.must_equal uibutton_text
106106
end
107107

108108
# TODO: 'string_attr_exact'
109109

110110
t 'find_ele_by_attr' do
111-
el_id = find_ele_by_attr('UIAStaticText', 'name', uibutton_text).instance_variable_get :@id
111+
el_id = find_ele_by_attr(UI::Inventory.static_text, 'name', uibutton_text).instance_variable_get :@id
112112
el_id.must_match(/\d+/)
113113
end
114114

@@ -117,37 +117,37 @@ def uibutton_text
117117
# no space after the !
118118
set_wait 1
119119
# empty array returned when no match
120-
found = !find_eles_by_attr('UIAStaticText', 'name', uibutton_text).empty?
120+
found = !find_eles_by_attr(UI::Inventory.static_text, 'name', uibutton_text).empty?
121121
found.must_equal true
122122

123-
found = !find_eles_by_attr('UIAStaticText', 'name', 'zz').empty?
123+
found = !find_eles_by_attr(UI::Inventory.static_text, 'name', 'zz').empty?
124124
found.must_equal false
125125
set_wait
126126
end
127127

128128
# TODO: 'string_attr_include'
129129

130130
t 'find_ele_by_attr_include' do
131-
el_text = find_ele_by_attr_include('UIAStaticText', :name, 'button').text
131+
el_text = find_ele_by_attr_include(UI::Inventory.static_text, :name, 'button').text
132132
el_text.must_equal uibutton_text
133133

134-
el_name = find_ele_by_attr_include('UIAStaticText', :name, 'button').name
134+
el_name = find_ele_by_attr_include(UI::Inventory.static_text, :name, 'button').name
135135
el_name.must_equal uibutton_text
136136
end
137137

138138
t 'find_eles_by_attr_include' do
139-
ele_count = find_eles_by_attr_include('UIAStaticText', :name, 'e').length
140-
ele_count.must_equal 19
139+
ele_count = find_eles_by_attr_include(UI::Inventory.static_text, :name, 'e').length
140+
ele_count.must_equal 20
141141
end
142142

143143
t 'first_ele' do
144-
first_ele('UIAStaticText').name.must_equal 'UICatalog'
144+
first_ele(UI::Inventory.static_text).name.must_equal 'UICatalog'
145145
end
146146

147147
t 'last_ele' do
148-
el = last_ele('UIAStaticText')
149-
el.text.must_equal 'Transitions'
150-
el.name.must_equal 'Transitions'
148+
el = last_ele(UI::Inventory.static_text)
149+
el.text.must_equal 'Shows UIViewAnimationTransitions'
150+
el.name.must_equal 'Shows UIViewAnimationTransitions'
151151
end
152152

153153
# t 'source' do # tested by get_source
@@ -156,10 +156,6 @@ def uibutton_text
156156
get_source.class.must_equal String
157157
end
158158

159-
t 'id' do
160-
id 'ButtonsExplain' # 'Various uses of UIButton'
161-
end
162-
163159
t 'invalid id should error' do
164160
proc { id 'does not exist' }.must_raise Selenium::WebDriver::Error::NoSuchElementError
165161

@@ -168,15 +164,15 @@ def uibutton_text
168164
end
169165

170166
t 'tag' do
171-
tag('UIATableCell').name.must_equal uibutton_text
167+
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
172168
end
173169

174170
t 'tags' do
175-
tags('UIATableCell').length.must_equal 12
171+
tags(UI::Inventory.table_cell).length.must_equal 12
176172
end
177173

178174
t 'find_eles_by_attr_include' do
179-
find_eles_by_attr_include('UIAStaticText', 'name', 'Use').length.must_equal 7
175+
find_eles_by_attr_include(UI::Inventory.static_text, 'name', 'Use').length.must_equal 7
180176
end
181177

182178
t 'get_page_class' do

ios_tests/lib/ios/specs/common/patch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def before_first
4848
ensure
4949
set_wait
5050
end
51-
value.must_equal 'Invalid locator strategy: css selector'
51+
value.must_equal "Locator Strategy 'css selector' is not supported for this session"
5252
end
5353
end
5454
end

ios_tests/lib/ios/specs/device/device.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def go_back
1919

2020
t 'lock' do
2121
lock 5
22-
tag('UIAButton').name.must_equal 'SlideToUnlock'
22+
tag(UI::Inventory.button).name.must_equal 'SlideToUnlock'
2323

2424
# It appears that lockForDuration doesn't.
2525
close_app
@@ -43,7 +43,7 @@ def go_back
4343
t 'close and launch' do
4444
close_app
4545
launch_app
46-
tag('UIANavigationBar').name.must_equal 'UICatalog'
46+
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
4747
end
4848

4949
t 'reset' do

ios_tests/lib/ios/specs/device/touch_actions.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
screen == 'Pickers'
66
end
77

8-
ele_index('UIAStaticText', 2).text.must_equal 'John Appleseed - 0'
9-
picker = ele_index('UIAPicker', 1)
8+
ele_index(UI::Inventory.static_text, 2).text.must_equal 'John Appleseed - 0'
9+
picker = ele_index(UI::Inventory.picker, 1)
1010
loc = picker.location.to_h
1111
size = picker.size.to_h
1212
start_x = loc[:x] + size[:width] / 2
1313
start_y = loc[:y] + size[:height] / 2
1414
swipe start_x: start_x, start_y: start_y, delta_x: start_x, delta_y: - 50
15-
ele_index('UIAStaticText', 2).text.must_equal 'Chris Armstrong - 0'
15+
ele_index(UI::Inventory.static_text, 2).text.must_equal 'Chris Armstrong - 0'
1616
end
1717
end
1818

ios_tests/lib/ios/specs/driver.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def sauce?
3636
actual = driver_attributes
3737
actual[:caps][:app] = File.basename actual[:caps][:app]
3838
expected = { caps: { platformName: 'ios',
39-
platformVersion: '9.3',
39+
platformVersion: '10.1',
40+
automationName: 'xcuitest',
4041
deviceName: 'iPhone Simulator',
4142
app: 'UICatalog.app' },
4243
custom_url: false,
@@ -191,19 +192,14 @@ def sauce?
191192
set_location latitude: 55, longitude: -72, altitude: 33
192193
end
193194

194-
# any script
195-
t 'execute_script' do
196-
execute_script %q(au.mainApp().getFirstWithPredicate("name contains[c] 'button'");)
197-
end
198-
199195
# any elements
200196
t 'find_elements' do
201-
find_elements(:class, 'UIATableCell').length.must_equal 12
197+
find_elements(:class, UI::Inventory.table_cell).length.must_equal 12
202198
end
203199

204200
# any element
205201
t 'find_element' do
206-
find_element(:class, 'UIAStaticText').class.must_equal Selenium::WebDriver::Element
202+
find_element(:class, UI::Inventory.static_text).class.must_equal Selenium::WebDriver::Element
207203
end
208204

209205
# settings

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ def nav_once
44
screen.must_equal catalog
55
wait_true do
66
text('alerts').click
7-
tag('UIANavigationBar').name == 'Alerts' # wait for true
7+
tag(UI::Inventory.navbar).name == 'Alerts' # wait for true
88
end
99

10-
tag('UIANavigationBar').name.must_equal 'Alerts'
10+
tag(UI::Inventory.navbar).name.must_equal 'Alerts'
1111

1212
# redefine method as no-op after it's invoked once
1313
self.class.send :define_method, :nav_once, proc {}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def before_first
2323
end
2424

2525
t 'last_text' do
26-
last_text.text.must_equal uiview_transitions
27-
last_text.name.must_equal uiview_transitions
26+
last_text.text.must_equal 'Shows UIViewAnimationTransitions'
27+
last_text.name.must_equal 'Shows UIViewAnimationTransitions'
2828
end
2929

3030
t 'text' do
@@ -35,7 +35,7 @@ def before_first
3535

3636
t 'texts' do
3737
exp = ['Controls', 'Various uses of UIControl', 'Various uses of UISegmentedControl']
38-
texts.length.must_equal 24
38+
texts.length.must_equal 25
3939
texts('trol').map(&:name).must_equal exp
4040
texts('uses').length.must_equal 7
4141
end

ios_tests/readme.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ ruby_lib's iOS tests. Requires `Ruby 1.9.3` or better.
1212

1313
`UICatalog6.1` is from [appium/appium](https://github.com/appium/appium/blob/master/assets/UICatalog6.1.app.zip)
1414

15-
The tests are now run against `iPhone 6 Simulator 9.3 (12F69)`
15+
There are two backend drivers available for iOS (automationName). UIAutomation which is supported up-to iOS 9.3 and XCUITest which is supported from 10.0 on. UIAutomation is deprecated but will continue to be supported for the time being.
1616

17+
By default, the tests are now run against `iPhone 6 Simulator 10.1 (14A345)`
1718
#### Documentation
1819

1920
- [Installing Appium on OS X](https://github.com/appium/ruby_console/blob/master/osx.md)
20-
- [Overview](https://github.com/appium/ruby_lib/blob/master/docs/docs.md)
21+
- [Overview](https://github.com/appium/ruby_lib/blob/master/docs/docs.md)
2122
- [iOS methods](https://github.com/appium/ruby_lib/blob/master/docs/ios_docs.md)
2223
- [Minitest Expectations](http://ruby-doc.org/stdlib-1.9.3/libdoc/minitest/spec/rdoc/MiniTest/Expectations.html)
2324

0 commit comments

Comments
 (0)