新手學appium-python unittest框架


#廢話不多說了,直接上代碼~
import
os import unittest from appium import webdriver from time import sleep # Returns abs path relative to this file and not cwd PATH = 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_caps['platformVersion'] = '4.3' desired_caps['deviceName'] = '192.168.56.101:5555' '''desired_caps['app'] = PATH( '../../../sample-code/apps/ContactManager/ContactManager.apk' )''' desired_caps['appPackage'] = 'com.android.calculator2' desired_caps['appActivity'] = '.Calculator' self.driver = webdriver.Remote('http://192.168.10.95:4723/wd/hub', desired_caps) def tearDown(self): self.driver.close_app() self.driver.quit() def test_add_contacts(self): '''el = self.driver.find_element_by_name("Add Contact") el.click() textfields = self.driver.find_elements_by_class_name("android.widget.EditText") textfields[0].send_keys("Appium User") textfields[2].send_keys("someone@appium.io") self.assertEqual('Appium User', textfields[0].text) self.assertEqual('someone@appium.io', textfields[2].text) self.driver.find_element_by_name("Save").click() # for some reason "save" breaks things alert = self.driver.switch_to_alert() # no way to handle alerts in Android self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click() self.driver.keyevent(3)''' self.driver.find_element_by_id('com.android.calculator2:id/digit9').click() if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests) unittest.TextTestRunner(verbosity=2).run(suite)

 

成功后的結果截圖~,參照下圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM