zoukankan      html  css  js  c++  java
  • Appium入门示例(python)

     

    安装Python依赖

     

    pip3.4 install nose
    pip3.4 install selenium
    pip3.4 install Appium-Python-Client
    
    

     

    运行测试用例android_contacts.py

     

    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.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("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)
    
    
    
    if __name__ == '__main__':
        suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
        unittest.TextTestRunner(verbosity=2).run(suite)
    
    

     

    运行用例结果:

     

    bixiaopeng@bixiaopengtekiMacBook-Pro python$ python3.4 android_contacts.py 
    test_add_contacts (__main__.ContactsAndroidTests) ... ok
    
    ----------------------------------------------------------------------
    Ran 1 test in 17.214s
    
    OK

     

  • 相关阅读:
    Unity3D Editor模式下批量修改prefab
    3D touch在Unity3D中的使用
    Unity中的协程是什么?
    Unity3D脚本调用Objective C代码实现游戏内购买
    WindowsPhone8拍照功能实现简介
    WindowsPhone App如何扩展能够使用的内存
    SVN 提交代码时提示文件已经存在解决办法
    iOS检查App新版本并更新新版本
    iOS存储数据字典到沙盒
    统计整个Xcode工程代码行数
  • 原文地址:https://www.cnblogs.com/wangcp-2014/p/5688916.html
Copyright © 2011-2022 走看看