2222from .helper .test_helper import (
2323 APIDEMO_PKG_NAME ,
2424 BaseTestCase ,
25+ is_ci ,
2526 wait_for_element
2627)
2728
@@ -73,20 +74,8 @@ def test_press_and_immediately_release_x_y(self):
7374 self .assertIsNotNone (el )
7475
7576 def test_press_and_wait (self ):
76- el1 = self .driver .find_element_by_accessibility_id ('Content' )
77- el2 = self .driver .find_element_by_accessibility_id ('Animation' )
78-
77+ self ._move_to_custom_adapter ()
7978 action = TouchAction (self .driver )
80- action .press (el1 ).move_to (el2 ).perform ()
81-
82- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Views' )
83- action .tap (el ).perform ()
84-
85- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Expandable Lists' )
86- action .tap (el ).perform ()
87-
88- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , '1. Custom Adapter' )
89- action .tap (el ).perform ()
9079
9180 el = wait_for_element (self .driver , MobileBy .ANDROID_UIAUTOMATOR ,
9281 'new UiSelector().text("People Names")' )
@@ -118,20 +107,8 @@ def test_press_and_moveto_x_y(self):
118107 self .assertIsNotNone (el )
119108
120109 def test_long_press (self ):
121- el1 = self .driver .find_element_by_accessibility_id ('Content' )
122- el2 = self .driver .find_element_by_accessibility_id ('Animation' )
123-
110+ self ._move_to_custom_adapter ()
124111 action = TouchAction (self .driver )
125- action .press (el1 ).move_to (el2 ).perform ()
126-
127- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Views' )
128- action .tap (el ).perform ()
129-
130- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Expandable Lists' )
131- action .tap (el ).perform ()
132-
133- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , '1. Custom Adapter' )
134- action .tap (el ).perform ()
135112
136113 el = wait_for_element (self .driver , MobileBy .ANDROID_UIAUTOMATOR ,
137114 'new UiSelector().text("People Names")' )
@@ -143,20 +120,10 @@ def test_long_press(self):
143120 self .assertIsNotNone (el )
144121
145122 def test_long_press_x_y (self ):
146- el1 = self . driver . find_element_by_accessibility_id ( 'Content' )
147- el2 = self .driver . find_element_by_accessibility_id ( 'Animation' )
148-
123+ if is_ci ():
124+ self .skipTest ( "Skip since this check is low robust due to hard-coded position." )
125+ self . _move_to_custom_adapter ()
149126 action = TouchAction (self .driver )
150- action .press (el1 ).move_to (el2 ).perform ()
151-
152- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Views' )
153- action .tap (el ).perform ()
154-
155- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Expandable Lists' )
156- action .tap (el ).perform ()
157-
158- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , '1. Custom Adapter' )
159- action .tap (el ).perform ()
160127
161128 # the element "People Names" is located at 430:310 (top left corner)
162129 # location can be changed by phone resolusion, OS version
@@ -168,13 +135,8 @@ def test_long_press_x_y(self):
168135 self .assertIsNotNone (el )
169136
170137 def test_drag_and_drop (self ):
171- el1 = self .driver .find_element_by_accessibility_id ('Content' )
172- el2 = self .driver .find_element_by_accessibility_id ('Animation' )
173- self .driver .scroll (el1 , el2 )
174-
175- el = self .driver .find_element_by_accessibility_id ('Views' )
138+ self ._move_to_views ()
176139 action = TouchAction (self .driver )
177- action .tap (el ).perform ()
178140
179141 el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Drag and Drop' )
180142 action .tap (el ).perform ()
@@ -185,17 +147,12 @@ def test_drag_and_drop(self):
185147 # dnd is stimulated by longpress-move_to-release
186148 action .long_press (dd3 ).move_to (dd2 ).release ().perform ()
187149
188- el = wait_for_element (self .driver , MobileBy .ID , '{}:id/drag_text ' .format (APIDEMO_PKG_NAME ))
189- self .assertTrue ('drag_dot_3 ' in el .text )
150+ el = wait_for_element (self .driver , MobileBy .ID , '{}:id/drag_result_text ' .format (APIDEMO_PKG_NAME ))
151+ self .assertTrue ('Dropped! ' in el .text )
190152
191153 def test_driver_drag_and_drop (self ):
192- el1 = self .driver .find_element_by_accessibility_id ('Content' )
193- el2 = self .driver .find_element_by_accessibility_id ('Animation' )
194- self .driver .scroll (el1 , el2 )
195-
196- el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Views' )
154+ self ._move_to_views ()
197155 action = TouchAction (self .driver )
198- action .tap (el ).perform ()
199156
200157 el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Drag and Drop' )
201158 action .tap (el ).perform ()
@@ -205,20 +162,40 @@ def test_driver_drag_and_drop(self):
205162
206163 self .driver .drag_and_drop (dd3 , dd2 )
207164
208- el = wait_for_element (self .driver , MobileBy .ID , '{}:id/drag_text ' .format (APIDEMO_PKG_NAME ))
209- self .assertTrue ('drag_dot_3 ' in el .text )
165+ el = wait_for_element (self .driver , MobileBy .ID , '{}:id/drag_result_text ' .format (APIDEMO_PKG_NAME ))
166+ self .assertTrue ('Dropped! ' in el .text )
210167
211168 def test_driver_swipe (self ):
212169 el = self .driver .find_element_by_accessibility_id ('Views' )
213170 action = TouchAction (self .driver )
214171 action .tap (el ).perform ()
215172
173+ wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Animation' )
216174 self .assertRaises (NoSuchElementException , self .driver .find_element_by_accessibility_id , 'ImageView' )
217175
218176 self .driver .swipe (100 , 1000 , 100 , 100 , 800 )
219- el = self .driver . find_element_by_accessibility_id ( 'ImageView' )
177+ el = wait_for_element ( self .driver , MobileBy . ACCESSIBILITY_ID , 'ImageView' )
220178 self .assertIsNotNone (el )
221179
180+ def _move_to_views (self ):
181+ el1 = self .driver .find_element_by_accessibility_id ('Content' )
182+ el2 = self .driver .find_element_by_accessibility_id ('Animation' )
183+ self .driver .scroll (el1 , el2 )
184+
185+ el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Views' )
186+ action = TouchAction (self .driver )
187+ action .tap (el ).perform ()
188+
189+ def _move_to_custom_adapter (self ):
190+ self ._move_to_views ()
191+ action = TouchAction (self .driver )
192+
193+ el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Expandable Lists' )
194+ action .tap (el ).perform ()
195+
196+ el = wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , '1. Custom Adapter' )
197+ action .tap (el ).perform ()
198+
222199
223200if __name__ == '__main__' :
224201 suite = unittest .TestLoader ().loadTestsFromTestCase (TouchActionTests )
0 commit comments