使用python寫appium用例

來源:互聯網
上載者:User

標籤:

安裝Python依賴
pip3.4 install nosepip3.4 install seleniumpip3.4 install Appium-Python-Client
執行測試用例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_caps[‘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.contactmanager‘        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_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("[email protected]")        self.assertEqual(‘Appium User‘, textfields[0].text)        self.assertEqual(‘[email protected]‘, 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)if __name__ == ‘__main__‘:    suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)    unittest.TextTestRunner(verbosity=2).run(suite)
執行用例結果:
[email protected] python$ python3.4 android_contacts.py test_add_contacts (__main__.ContactsAndroidTests) ... ok----------------------------------------------------------------------Ran 1 test in 17.214sOK
公眾帳號: wirelessqa

關於

作者: 畢小朋 | 老 畢 郵箱: [email protected]

微博: @WirelessQA 部落格: http://blog.csdn.net/wirelessqa

著作權聲明:本文部落格原創文章,部落格,未經同意,不得轉載。

使用python寫appium用例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.