Skip to content

Commit e765d1f

Browse files
authored
Fix tests for xcuitest strategy (#408)
* switch previous version or xcuitest version * use class for tag to make it stable * add comments and revert js commands for appium * fix and comment out use accessibiliyt id as id and skip some tests * use id directory * raise error when notimplemented error * move id test * raise error when xcuitests is selected under appium1.6.0 * fix pinch and zoom for xcuitest * fix robocop * remove unused hide keyboard * fix tests * update comments and required version * add error and documentations * get status by WebDriverAgent directly and available custom url for WDA * use capability's platformVersion instead of call WDA directly * arrange some comments * make accesable each class name
1 parent cfabca1 commit e765d1f

27 files changed

+462
-188
lines changed

android_tests/lib/android/specs/common/device_touchaction.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
describe 'common/device_touchaction' do
33
t 'action_chain' do
44
wait do
5-
e = find_element(:name, 'Accessibility')
5+
e = text('Accessibility')
66
Appium::TouchAction.new.press(element: e, x: 0.5, y: 0.5).release(element: e).perform
77
end
8-
wait { find_element(:name, 'Custom View') }
8+
wait { text('Custom View') }
99
back
1010
wait { text_exact 'NFC' }
1111
end

docs/index_paths.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ that appium calculates when the page source is requested. Note this is not the s
88
The index path can be used by calling [getElementByIndexPath]( https://github.com/appium/appium-uiauto/blob/af1befa8208074686cd38b845ddefabc057106fc/uiauto/lib/mechanic-ext/xpath-ext.js#L239):
99

1010
```ruby
11-
# ruby example
11+
# ruby example # For Appium(automation name), not XCUITest
1212
execute_script('$.getElementByIndexPath("/0/1/1/10/0")').text # Alerts
1313
```
1414

1515
Internally what happens is `/0/1/1/10/0` is transformed into `1/1/10/0` and executed as follows:
1616

1717
```ruby
18-
# ruby example
18+
# ruby example # For Appium(automation name), not XCUITest
1919
execute_script('$.mainApp().elements()[1].elements()[1].elements()[10].elements()[0]').text # Alerts
2020
```
2121

ios_tests/appium.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
platformName = "ios"
33
platformVersion = "10.1"
44
deviceName ="iPhone Simulator"
5-
automationName = 'xcuitest'
5+
automationName = 'XCUITest'
66
app = "./UICatalog.app"
77

88
[appium_lib]

ios_tests/lib/common.rb

+3-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ def leave_textfields
1818
def go_to_textfields
1919
screen.must_equal catalog
2020
wait_true do
21-
text('textfield').click
21+
UI::Inventory.xcuitest? ? find_element(:name, 'TextFields').click : text('textfield').click
2222
screen == 'TextFields' # wait for screen transition
2323
end
24-
25-
screen.must_equal 'TextFields'
2624
end
2725

2826
def screen
29-
$driver.find_element(:class, 'UIANavigationBar').name
27+
$driver.find_element(:class, UI::Inventory.navbar).name
3028
end
3129

3230
def catalog
@@ -35,14 +33,10 @@ def catalog
3533

3634
module UI
3735
module Inventory
38-
private
39-
4036
def self.xcuitest?
41-
$driver.automation_name && $driver.automation_name == 'xcuitest'
37+
$driver.automation_name_is_xcuitest?
4238
end
4339

44-
public
45-
4640
def self.navbar
4741
if xcuitest?
4842
'XCUIElementTypeNavigationBar'

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,20 @@ def uibutton_text
137137

138138
t 'find_eles_by_attr_include' do
139139
ele_count = find_eles_by_attr_include(UI::Inventory.static_text, :name, 'e').length
140-
ele_count.must_equal 20
140+
expected = UI::Inventory.xcuitest? ? 20 : 19
141+
ele_count.must_equal expected
141142
end
142143

143144
t 'first_ele' do
144145
first_ele(UI::Inventory.static_text).name.must_equal 'UICatalog'
145146
end
146147

147148
t 'last_ele' do
149+
expected = UI::Inventory.xcuitest? ? 'Shows UIViewAnimationTransitions' : 'Transitions'
150+
148151
el = last_ele(UI::Inventory.static_text)
149-
el.text.must_equal 'Shows UIViewAnimationTransitions'
150-
el.name.must_equal 'Shows UIViewAnimationTransitions'
152+
el.text.must_equal expected
153+
el.name.must_equal expected
151154
end
152155

153156
# t 'source' do # tested by get_source
@@ -181,10 +184,7 @@ def uibutton_text
181184
end
182185

183186
# TODO: write tests
184-
# get_page_class
185187
# page_class
186-
# tag
187-
# tags
188188
# px_to_window_rel
189189
# lazy_load_strings
190190
# xml_keys

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def go_back
1818
end
1919

2020
t 'lock' do
21+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
22+
2123
lock 5
2224
tag(UI::Inventory.button).name.must_equal 'SlideToUnlock'
2325

@@ -32,11 +34,15 @@ def go_back
3234
end
3335

3436
t 'app_installed' do
37+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
38+
3539
installed = app_installed? 'Derrp'
3640
installed.must_equal false
3741
end
3842

3943
t 'shake' do
44+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
45+
4046
shake
4147
end
4248

@@ -75,23 +81,23 @@ def go_back
7581
end
7682

7783
t 'swipe' do
78-
swipe start_x: 75, start_y: 500, delta_x: 75, delta_y: 0, duration: 800
79-
end
80-
81-
t 'pinch & zoom' do
82-
wait { id('ImagesExplain').click }
83-
# both of these appear to do nothing on iOS 8
84-
zoom 200
85-
pinch 75
86-
go_back
84+
swipe start_x: 75, start_y: 500, delta_x: 0, delta_y: -500, duration: 800
8785
end
8886

8987
t 'pull_file' do
88+
# Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command.
89+
# Original error: Cannot read property 'getDir' of undefined
90+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
91+
9092
read_file = pull_file 'Library/AddressBook/AddressBook.sqlitedb'
9193
read_file.start_with?('SQLite format').must_equal true
9294
end
9395

9496
t 'pull_folder' do
97+
# Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command.
98+
# Original error: Cannot read property 'getDir' of undefined
99+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
100+
95101
data = pull_folder 'Library/AddressBook'
96102
data.length.must_be :>, 1
97103
end

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
# rake ios[device/multi_touch]
12
describe 'device/multi_touch' do
2-
t {} # place holder test
3+
def before_first
4+
screen.must_equal catalog
5+
end
6+
7+
# go back to the main page
8+
def go_back
9+
back
10+
wait { !exists { id 'ArrowButton' } } # successfully transitioned back
11+
end
12+
13+
t 'before_first' do
14+
before_first
15+
end
16+
17+
t 'pinch & zoom' do
18+
wait { id('Images').click }
19+
# both of these appear to do nothing on iOS 8
20+
zoom 200
21+
pinch 75
22+
go_back
23+
end
324
end
425

526
# TODO: write tests

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
# rake ios[device/touch_actions]
12
describe 'device/touch_actions' do
3+
def after_last
4+
back_click
5+
end
6+
27
t 'swipe_default_duration' do
38
wait_true do
4-
text('pickers').click
9+
wait { UI::Inventory.xcuitest? ? find_element(:name, 'Pickers').click : text('pickers').click }
510
screen == 'Pickers'
611
end
712

@@ -11,9 +16,13 @@
1116
size = picker.size.to_h
1217
start_x = loc[:x] + size[:width] / 2
1318
start_y = loc[:y] + size[:height] / 2
14-
swipe start_x: start_x, start_y: start_y, delta_x: start_x, delta_y: - 50
19+
swipe start_x: start_x, start_y: start_y, delta_x: 0, delta_y: - 50
1520
ele_index(UI::Inventory.static_text, 2).text.must_equal 'Chris Armstrong - 0'
1621
end
22+
23+
t 'after_last' do
24+
after_last
25+
end
1726
end
1827

1928
# TODO: write tests

ios_tests/lib/ios/specs/driver.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def sauce?
3737
actual[:caps][:app] = File.basename actual[:caps][:app]
3838
expected = { caps: { platformName: 'ios',
3939
platformVersion: '10.1',
40-
automationName: 'xcuitest',
40+
automationName: 'XCUITest',
4141
deviceName: 'iPhone Simulator',
4242
app: 'UICatalog.app' },
4343
custom_url: false,
@@ -146,7 +146,11 @@ def sauce?
146146
end
147147

148148
t 'driver' do
149-
driver.browser.must_equal :iOS
149+
driver.browser.must_be_empty
150+
end
151+
152+
t 'automation_name_is_xcuitest?' do
153+
automation_name_is_xcuitest?.must_equal UI::Inventory.xcuitest?
150154
end
151155

152156
#
@@ -189,6 +193,7 @@ def sauce?
189193

190194
# simple integration sanity test to check for unexpected exceptions
191195
t 'set_location' do
196+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
192197
set_location latitude: 55, longitude: -72, altitude: 33
193198
end
194199

@@ -204,10 +209,13 @@ def sauce?
204209

205210
# settings
206211
t 'get settings' do
212+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
207213
get_settings.wont_be_nil
208214
end
209215

210216
t 'update settings' do
217+
fail NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
218+
211219
update_settings cyberdelia: 'open'
212220
get_settings['cyberdelia'].must_equal 'open'
213221
end

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
def nav_once
44
screen.must_equal catalog
55
wait_true do
6-
text('alerts').click
6+
UI::Inventory.xcuitest? ? find_element(:name, 'Alerts').click : text('alerts').click
77
tag(UI::Inventory.navbar).name == 'Alerts' # wait for true
88
end
99

10-
tag(UI::Inventory.navbar).name.must_equal 'Alerts'
11-
1210
# redefine method as no-op after it's invoked once
1311
self.class.send :define_method, :nav_once, proc {}
1412
end
1513

1614
def after_last
17-
alert_accept if exists { text('UIActionSheet <title>') }
15+
alert_accept if exists do
16+
UI::Inventory.xcuitest? ? find_elements(:name, 'UIActionSheet <title>') : text('UIActionSheet <title>')
17+
end
1818
back_click
1919
screen.must_equal catalog
2020
sleep 1
@@ -27,9 +27,13 @@ def after_last
2727

2828
def open_alert
2929
wait_true do
30-
return true if exists { text('UIActionSheet <title>') }
31-
text('Show OK-Cancel').click
32-
text('UIActionSheet <title>').displayed?
30+
if UI::Inventory.xcuitest?
31+
find_element(:name, 'Show OK-Cancel').click
32+
find_element(:name, 'UIActionSheet <title>').displayed?
33+
else
34+
text('Show OK-Cancel').click
35+
text('UIActionSheet <title>').displayed?
36+
end
3337
end
3438
end
3539

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def before_first
44
screen.must_equal catalog
55
# nav to buttons activity
6-
wait { text('buttons').click }
6+
wait { UI::Inventory.xcuitest? ? find_element(:name, 'Buttons').click : text('buttons').click }
77
end
88

99
def after_last
@@ -21,14 +21,16 @@ def gray
2121

2222
t 'button' do
2323
# by index
24-
button(3).name.must_equal gray
24+
button(3).name.must_equal gray # or UIButtonTypeInfoDark in XCUITest
2525

2626
# by name contains
2727
button('ray').name.must_equal gray
2828
end
2929

3030
t 'buttons' do
3131
exp = ['Back', 'Back', 'Gray', 'Right pointing arrow']
32+
exp.concat ['Custom Text', 'More info', 'More info', 'More info', 'Add contact'] if UI::Inventory.xcuitest?
33+
3234
target_buttons = buttons('a')
3335
target_buttons.map(&:name).must_equal exp
3436
target_buttons.length.must_equal exp.length
@@ -39,7 +41,8 @@ def gray
3941
end
4042

4143
t 'last_button' do
42-
last_button.name.must_equal 'Rounded'
44+
expected = UI::Inventory.xcuitest? ? 'Add contact' : 'Rounded'
45+
last_button.name.must_equal expected
4346
end
4447

4548
t 'button_exact' do

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

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

2525
t 'last_text' do
26-
last_text.text.must_equal 'Shows UIViewAnimationTransitions'
27-
last_text.name.must_equal 'Shows UIViewAnimationTransitions'
26+
expected = UI::Inventory.xcuitest? ? 'Shows UIViewAnimationTransitions' : 'Transitions'
27+
28+
last_text.text.must_equal expected
29+
last_text.name.must_equal expected
2830
end
2931

3032
t 'text' do
@@ -35,7 +37,7 @@ def before_first
3537

3638
t 'texts' do
3739
exp = ['Controls', 'Various uses of UIControl', 'Various uses of UISegmentedControl']
38-
texts.length.must_equal 25
40+
texts.length.must_equal(UI::Inventory.xcuitest? ? 25 : 24)
3941
texts('trol').map(&:name).must_equal exp
4042
texts('uses').length.must_equal 7
4143
end

0 commit comments

Comments
 (0)