Installing Python dependencies
pip3.4 install nosepip3.4 install seleniumpip3.4 install Appium-Python-Client
Run the test case android_contacts.py
Import osimport unittestfrom appium import webdriverfrom time import sleep# Returns abs path relative to this file and not Cwdpath = Lambda P:os.path.abspath (os.path.join (Os.path.dirname (__file__), p)) class Contactsandroidtests (UnitTest. TestCase): def setUp (self): Desired_caps = {} desired_caps[' platformname '] = ' Android ' Desired_cap s[' platformversion ' = ' 4.4 ' desired_caps[' devicename '] = ' 192.168.56.111:5555 ' desired_caps[' app ' = PATH ( ‘.. /.. /.. /sample-code/apps/contactmanager/contactmanager.apk ') desired_caps[' apppackage '] = ' Com.example.android.con Tactmanager ' desired_caps[' appactivity '] = '. Contactmanager ' Self.driver = webdriver. Remote (' Http://0.0.0.0:4723/wd/hub ', desired_caps) def tearDown (self): Self.driver.quit () def TEST_ADD_CONTAC TS (self): el = Self.driver.find_element_by_name ("Add Contact") El.click () Textfields = self.driver.fi Nd_elements_by_class_name ("anDroid.widget.EditText ") Textfields[0].send_keys (" Appium User ") Textfields[2].send_keys (" [Email protecte D] ") self.assertequal (' Appium User ', Textfields[0].text) self.assertequal (' [email protected] ', Textfiel Ds[2].text) Self.driver.find_element_by_name ("Save"). Click () # for some reason "save" breaks things A Lert = Self.driver.switch_to_alert () # no-to-handle alerts in Android Self.driver.find_element_by_androi D_uiautomator (' New Uiselector (). Clickable (True) '). Click () self.driver.keyevent (3) if __name__ = = ' __main__ ': Suit E = UnitTest. Testloader (). Loadtestsfromtestcase (contactsandroidtests) unittest. Texttestrunner (verbosity=2). Run (Suite)
To run a use case result:
[email protected] python$ python3.4 android_contacts.py test_add_contacts (__main__.ContactsAndroidTests) ... ok----------------------------------------------------------------------Ran 1 test in 17.214sOK
Public account: WIRELESSQA
About
Author: Bi Xiaobong | Old bi e-mail: [email protected]
Weibo: @WirelessQA Blog: HTTP://BLOG.CSDN.NET/WIRELESSQA