2121from time import sleep
2222from dateutil .parser import parse
2323
24+ from appium import webdriver
2425from appium .webdriver .applicationstate import ApplicationState
26+ from appium .webdriver .common .mobileby import MobileBy
2527from selenium .common .exceptions import NoSuchElementException
26- from selenium .webdriver .common .by import By
27- from selenium .webdriver .support import expected_conditions as EC
28- from selenium .webdriver .support .ui import WebDriverWait
2928
30- from appium import webdriver
3129import desired_capabilities
30+ from helper .test_helper import wait_for_element
3231
3332
3433# the emulator is sometimes slow and needs time to think
@@ -49,7 +48,7 @@ def tearDown(self):
4948
5049 def test_screen_record (self ):
5150 self .driver .start_recording_screen (timeLimit = 10 , forcedRestart = True )
52- sleep (5 )
51+ sleep (10 )
5352 result = self .driver .stop_recording_screen ()
5453 self .assertTrue (len (result ) > 0 )
5554
@@ -196,31 +195,22 @@ def test_open_notifications(self):
196195 def test_set_text (self ):
197196 self .driver .find_element_by_android_uiautomator (
198197 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));' ).click ()
199- WebDriverWait (self .driver , SLEEPY_TIME ).until (
200- EC .presence_of_element_located ((By .ACCESSIBILITY_ID , 'Controls' ))
201- )
202- self .driver .find_element_by_accessibility_id ('Controls' ).click ()
203-
204- WebDriverWait (self .driver , SLEEPY_TIME ).until (
205- EC .presence_of_element_located ((By .ACCESSIBILITY_ID , '1. Light Theme' ))
206- )
207- self .driver .find_element_by_accessibility_id ('1. Light Theme' ).click ()
208-
209- WebDriverWait (self .driver , SLEEPY_TIME ).until (
210- EC .presence_of_element_located ((By .CLASS_NAME , 'android.widget.EditText' ))
211- )
212- el = self .driver .find_element_by_class_name ('android.widget.EditText' )
198+
199+ wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , 'Controls' , SLEEPY_TIME ).click ()
200+ wait_for_element (self .driver , MobileBy .ACCESSIBILITY_ID , '1. Light Theme' , SLEEPY_TIME ).click ()
201+
202+ el = wait_for_element (self .driver , MobileBy .CLASS_NAME , 'android.widget.EditText' , SLEEPY_TIME )
213203 el .send_keys ('original text' )
214204 el .set_text ('new text' )
215205
216206 self .assertEqual ('new text' , el .text )
217207
218208 def test_send_keys (self ):
219- self . driver . find_element_by_xpath ( "//android.widget.TextView[@ text= 'App']" ). click ()
220- self .driver . find_element_by_xpath ( "//android.widget.TextView[@text='Activity']" ). click ()
221- self . driver . find_element_by_xpath ( "//android.widget.TextView[@text='Custom Title ']" ).click ()
209+ for text in [ 'App' , 'Activity' , 'Custom Title' ]:
210+ wait_for_element ( self .driver , MobileBy . XPATH ,
211+ "//android.widget.TextView[@text='{} ']" . format ( text ), SLEEPY_TIME ).click ()
222212
223- el = self .driver .find_element (By .ID , 'com.example.android.apis:id/left_text_edit' )
213+ el = self .driver .find_element (MobileBy .ID , 'com.example.android.apis:id/left_text_edit' )
224214 el .send_keys (' text' )
225215
226216 self .assertEqual ('Left is best text' , el .text )
@@ -236,8 +226,8 @@ def test_start_activity_other_app(self):
236226 self .driver .start_activity ("com.example.android.apis" , ".ApiDemos" )
237227 self ._assert_activity_contains ('Demos' )
238228
239- self .driver .start_activity ("com.android.contacts " , ".ContactsListActivity " )
240- self ._assert_activity_contains ('Contact ' )
229+ self .driver .start_activity ("com.android.calculator2 " , ".Calculator " )
230+ self ._assert_activity_contains ('Calculator ' )
241231
242232 def _assert_activity_contains (self , activity ):
243233 current = self .driver .current_activity
@@ -248,9 +238,9 @@ def test_get_settings(self):
248238 self .assertIsNotNone (settings )
249239
250240 def test_update_settings (self ):
251- self .driver .update_settings ({"cyberdelia " : "open" })
241+ self .driver .update_settings ({"waitForIdleTimeout " : 10001 })
252242 settings = self .driver .get_settings ()
253- self .assertEqual (settings ["cyberdelia " ], "open" )
243+ self .assertEqual (settings ["waitForIdleTimeout " ], 10001 )
254244
255245 def test_toggle_location_services (self ):
256246 self .driver .toggle_location_services ()
0 commit comments