Skip to content

Commit 6ee404d

Browse files
authored
refactor: Separate xcuitest more (#639)
* add test sample * add rake style * update parallel tests * separate xcuitest related code more * separate some methods and stop using for tests * rename test methods * remove unused methods from xcuitest and appium * fix rubocop
1 parent 8a7c386 commit 6ee404d

21 files changed

+530
-338
lines changed

ios_tests/lib/common.rb

+46-40
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,73 @@ def leave_textfields
1818
def go_to_textfields
1919
screen.must_equal catalog
2020
wait_true do
21-
UI::Inventory.xcuitest? ? find_element(:name, 'TextFields').click : text('textfield').click
21+
automation_name_is_xcuitest? ? find_element(:name, 'TextFields').click : text('textfield').click
2222
screen == 'TextFields' # wait for screen transition
2323
end
2424
end
2525

2626
def screen
27-
$driver.find_element(:class, UI::Inventory.navbar).name
27+
$driver.find_element(:class, ui_ios.navbar).name
2828
end
2929

3030
def catalog
3131
'UICatalog'
3232
end
3333

34-
module UI
35-
module Inventory
36-
def self.xcuitest?
37-
$driver.automation_name_is_xcuitest?
38-
end
34+
def ui_ios
35+
UI.new($driver)
36+
end
3937

40-
def self.navbar
41-
xcuitest? ? 'XCUIElementTypeNavigationBar' : 'UIANavigationBar'
42-
end
38+
class UI
39+
def initialize(driver)
40+
@driver = driver
41+
end
4342

44-
def self.button
45-
xcuitest? ? 'XCUIElementTypeButton' : 'UIAButton'
46-
end
43+
def xcuitest?
44+
@driver.automation_name_is_xcuitest?
45+
end
4746

48-
def self.static_text
49-
xcuitest? ? 'XCUIElementTypeStaticText' : 'UIAStaticText'
50-
end
47+
def navbar
48+
xcuitest? ? 'XCUIElementTypeNavigationBar' : 'UIANavigationBar'
49+
end
5150

52-
def self.text_field
53-
xcuitest? ? 'XCUIElementTypeTextField' : 'UIATextField'
54-
end
51+
def button
52+
xcuitest? ? 'XCUIElementTypeButton' : 'UIAButton'
53+
end
5554

56-
def self.secure_text_field
57-
xcuitest? ? 'XCUIElementTypeSecureTextField' : 'UIASecureTextField'
58-
end
55+
def static_text
56+
xcuitest? ? 'XCUIElementTypeStaticText' : 'UIAStaticText'
57+
end
5958

60-
def self.picker
61-
xcuitest? ? 'XCUIElementTypePicker' : 'UIAPicker'
62-
end
59+
def text_field
60+
xcuitest? ? 'XCUIElementTypeTextField' : 'UIATextField'
61+
end
6362

64-
def self.action_sheet
65-
xcuitest? ? 'XCUIElementTypeActionSheet' : 'UIActionSheet'
66-
end
63+
def secure_text_field
64+
xcuitest? ? 'XCUIElementTypeSecureTextField' : 'UIASecureTextField'
65+
end
6766

68-
def self.table
69-
xcuitest? ? 'XCUIElementTypeTable' : 'UIATable'
70-
end
67+
def picker
68+
xcuitest? ? 'XCUIElementTypePicker' : 'UIAPicker'
69+
end
70+
71+
def action_sheet
72+
xcuitest? ? 'XCUIElementTypeActionSheet' : 'UIActionSheet'
73+
end
7174

72-
def self.table_cell
73-
xcuitest? ? 'XCUIElementTypeCell' : 'UIATableCell'
74-
end
75+
def table
76+
xcuitest? ? 'XCUIElementTypeTable' : 'UIATable'
77+
end
7578

76-
def self.other
77-
xcuitest? ? 'XCUIElementTypeOther' : raise('unknown UIA element: other')
78-
end
79+
def table_cell
80+
xcuitest? ? 'XCUIElementTypeCell' : 'UIATableCell'
81+
end
82+
83+
def other
84+
xcuitest? ? 'XCUIElementTypeOther' : raise('unknown UIA element: other')
85+
end
7986

80-
def self.status_bar
81-
xcuitest? ? 'XCUIElementTypeStatusBar' : 'UIAStatusBar'
82-
end
87+
def status_bar
88+
xcuitest? ? 'XCUIElementTypeStatusBar' : 'UIAStatusBar'
8389
end
8490
end

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

+19-19
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(UI::Inventory.navbar).name.must_equal 'UICatalog'
73+
tag(ui_ios.navbar).name.must_equal 'UICatalog'
7474
# nav to new page.
7575
wait_true do
7676
text('buttons').click
77-
tag(UI::Inventory.navbar).name == 'Buttons'
77+
tag(ui_ios.navbar).name == 'Buttons'
7878
end
7979

80-
tag(UI::Inventory.navbar).name.must_equal 'Buttons'
80+
tag(ui_ios.navbar).name.must_equal 'Buttons'
8181
# go back
8282
back_click
8383
# start page
84-
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
84+
tag(ui_ios.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("//#{UI::Inventory.static_text}").name.must_equal 'UICatalog'
93+
xpath("//#{ui_ios.static_text}").name.must_equal 'UICatalog'
9494
end
9595

9696
t 'xpaths' do
97-
xpaths("//#{UI::Inventory.static_text}").length.must_equal 25
97+
xpaths("//#{ui_ios.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(UI::Inventory.static_text, 2).name.must_equal uibutton_text
105+
ele_index(ui_ios.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(UI::Inventory.static_text, 'name', uibutton_text).instance_variable_get :@id
111+
el_id = find_ele_by_attr(ui_ios.static_text, 'name', uibutton_text).instance_variable_get :@id
112112
el_id.must_match(/\d+/)
113113
end
114114

@@ -117,10 +117,10 @@ 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(UI::Inventory.static_text, 'name', uibutton_text).empty?
120+
found = !find_eles_by_attr(ui_ios.static_text, 'name', uibutton_text).empty?
121121
found.must_equal true
122122

123-
found = !find_eles_by_attr(UI::Inventory.static_text, 'name', 'zz').empty?
123+
found = !find_eles_by_attr(ui_ios.static_text, 'name', 'zz').empty?
124124
found.must_equal false
125125
set_wait
126126
end
@@ -144,16 +144,16 @@ def uibutton_text
144144
# TODO: 'string_attr_include'
145145

146146
t 'find_ele_by_attr_include' do
147-
el_text = find_ele_by_attr_include(UI::Inventory.static_text, :name, 'button').text
147+
el_text = find_ele_by_attr_include(ui_ios.static_text, :name, 'button').text
148148
el_text.must_equal uibutton_text
149149

150-
el_name = find_ele_by_attr_include(UI::Inventory.static_text, :name, 'button').name
150+
el_name = find_ele_by_attr_include(ui_ios.static_text, :name, 'button').name
151151
el_name.must_equal uibutton_text
152152
end
153153

154154
t 'find_eles_by_attr_include' do
155-
ele_count = find_eles_by_attr_include(UI::Inventory.static_text, :name, 'e').length
156-
expected = UI::Inventory.xcuitest? ? 20 : 19
155+
ele_count = find_eles_by_attr_include(ui_ios.static_text, :name, 'e').length
156+
expected = automation_name_is_xcuitest? ? 20 : 19
157157
ele_count.must_equal expected
158158
end
159159

@@ -170,13 +170,13 @@ def uibutton_text
170170
end
171171

172172
t 'first_ele' do
173-
first_ele(UI::Inventory.static_text).name.must_equal 'UICatalog'
173+
first_ele(ui_ios.static_text).name.must_equal 'UICatalog'
174174
end
175175

176176
t 'last_ele' do
177177
expected = 'Transitions'
178178

179-
el = last_ele(UI::Inventory.static_text)
179+
el = last_ele(ui_ios.static_text)
180180
el.text.must_equal expected
181181
el.name.must_equal expected
182182
end
@@ -195,15 +195,15 @@ def uibutton_text
195195
end
196196

197197
t 'tag' do
198-
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
198+
tag(ui_ios.navbar).name.must_equal 'UICatalog'
199199
end
200200

201201
t 'tags' do
202-
tags(UI::Inventory.table_cell).length.must_equal 12
202+
tags(ui_ios.table_cell).length.must_equal 12
203203
end
204204

205205
t 'find_eles_by_attr_include_length' do
206-
find_eles_by_attr_include(UI::Inventory.static_text, 'name', 'Use').length.must_equal 7
206+
find_eles_by_attr_include(ui_ios.static_text, 'name', 'Use').length.must_equal 7
207207
end
208208

209209
t 'get_page_class' do

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ def go_back
1818
end
1919

2020
t 'lock' do
21-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
22-
2321
lock 5
24-
tag(UI::Inventory.button).name.must_equal 'SlideToUnlock'
22+
tag(ui_ios).name.must_equal 'SlideToUnlock'
2523

2624
# It appears that lockForDuration doesn't.
2725
close_app
@@ -34,22 +32,18 @@ def go_back
3432
end
3533

3634
t 'app_installed' do
37-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
38-
3935
installed = app_installed? 'Derrp'
4036
installed.must_equal false
4137
end
4238

4339
t 'shake' do
44-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
45-
4640
shake
4741
end
4842

4943
t 'close and launch' do
5044
close_app
5145
launch_app
52-
tag(UI::Inventory.navbar).name.must_equal 'UICatalog'
46+
tag(ui_ios.navbar).name.must_equal 'UICatalog'
5347
end
5448

5549
t 'background_app homescreen' do
@@ -118,17 +112,13 @@ def go_back
118112
t 'pull_file' do
119113
# Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command.
120114
# Original error: Cannot read property 'getDir' of undefined
121-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
122-
123115
read_file = pull_file 'Library/AddressBook/AddressBook.sqlitedb'
124116
read_file.start_with?('SQLite format').must_equal true
125117
end
126118

127119
t 'pull_folder' do
128120
# Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command.
129121
# Original error: Cannot read property 'getDir' of undefined
130-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
131-
132122
data = pull_folder 'Library/AddressBook'
133123
data.length.must_be :>, 1
134124
end

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ def after_last
66

77
t 'swipe_default_duration' do
88
wait_true do
9-
wait { UI::Inventory.xcuitest? ? find_element(:name, 'Pickers').click : text('pickers').click }
9+
wait { automation_name_is_xcuitest? ? find_element(:name, 'Pickers').click : text('pickers').click }
1010
screen == 'Pickers'
1111
end
1212

13-
ele_index(UI::Inventory.static_text, 2).text.must_equal 'John Appleseed - 0'
14-
picker = ele_index(UI::Inventory.picker, 1)
13+
ele_index(ui_ios.static_text, 2).text.must_equal 'John Appleseed - 0'
14+
picker = ele_index(ui_ios.picker, 1)
1515
loc = picker.location.to_h
1616
size = picker.size.to_h
1717
start_x = loc[:x] + size[:width] / 2
@@ -45,7 +45,7 @@ def after_last
4545
# [HTTP] <-- POST /wd/hub/session/8b651f03-0fbc-43f0-aaf2-243d0650f6aa/touch/perform 200 1895 ms - 74
4646
# rubocop:enable Metrics/LineLength
4747
Appium::TouchAction.new.swipe(start_x: start_x, start_y: start_y, offset_x: 0, offset_y: - 50).perform
48-
ele_index(UI::Inventory.static_text, 2).text.must_equal 'Chris Armstrong - 0'
48+
ele_index(ui_ios.static_text, 2).text.must_equal 'Chris Armstrong - 0'
4949
end
5050

5151
t 'swipe_coordinates_end_x_end_y' do

ios_tests/lib/ios/specs/driver.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def sauce?
233233
end
234234

235235
t 'automation_name_is_xcuitest?' do
236-
automation_name_is_xcuitest?.must_equal UI::Inventory.xcuitest?
236+
automation_name_is_xcuitest?.must_equal automation_name_is_xcuitest?
237237
end
238238

239239
#
@@ -276,23 +276,21 @@ def sauce?
276276

277277
# simple integration sanity test to check for unexpected exceptions
278278
t 'set_location' do
279-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
280279
set_location latitude: 55, longitude: -72, altitude: 33
281280
end
282281

283282
# any elements
284283
t 'find_elements' do
285-
find_elements(:class, UI::Inventory.table_cell).length.must_equal 12
284+
find_elements(:class, ui_ios.table_cell).length.must_equal 12
286285
end
287286

288287
# any element
289288
t 'find_element' do
290-
find_element(:class, UI::Inventory.static_text).class.must_equal Selenium::WebDriver::Element
289+
find_element(:class, ui_ios.static_text).class.must_equal Selenium::WebDriver::Element
291290
end
292291

293292
# settings
294293
t 'get settings' do
295-
raise NotImplementedError, "XCUITest(Appium1.6.2) doesn't support yet" if UI::Inventory.xcuitest?
296294
get_settings.wont_be_nil
297295
end
298296

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

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

1010
# redefine method as no-op after it's invoked once
@@ -13,7 +13,7 @@ def nav_once
1313

1414
def after_last
1515
alert_accept if exists do
16-
UI::Inventory.xcuitest? ? find_elements(:name, 'UIActionSheet <title>') : text('UIActionSheet <title>')
16+
automation_name_is_xcuitest? ? find_elements(:name, 'UIActionSheet <title>') : text('UIActionSheet <title>')
1717
end
1818
back_click
1919
screen.must_equal catalog
@@ -27,7 +27,7 @@ def after_last
2727

2828
def open_alert
2929
wait_true do
30-
if UI::Inventory.xcuitest?
30+
if automation_name_is_xcuitest?
3131
find_element(:name, 'Show OK-Cancel').click
3232
find_element(:name, 'UIActionSheet <title>').displayed?
3333
else

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

+1-1
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 { UI::Inventory.xcuitest? ? find_element(:name, 'Buttons').click : text('buttons').click }
6+
wait { automation_name_is_xcuitest? ? find_element(:name, 'Buttons').click : text('buttons').click }
77
end
88

99
def after_last

0 commit comments

Comments
 (0)