使用python编写appium用例
2015-12-09 20:15
281 查看
安装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
相关文章推荐
- 用idea编写appium用例
- android常见错误
- appium在MAC上环境搭建
- iOS symbolicatecrash工具crash日志分析
- Android获取图片并裁剪
- ZIGBEE中SerialApp_ProcessEvent分析
- Android静态变量的生命周期
- Android控件之ListView ChoickModel 单选、多选模式
- Unity 协程与线程区别
- android JNI常用添加log方法
- 关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都需要业心照料
- App开发需要注意的8条
- 解决 android 高低版本 webView 里内容 自适应屏幕的终极方法
- android 关于paint的设置
- swift第四天学习
- android 设计模式之Listview不同类型Item利用工厂模式的复用
- 在Web应用中接入微信支付的流程之极简清晰版
- android屏幕适配终极指南(一):DPI,分辨率和屏幕尺寸
- swift学习日记(三) 函数 闭包
- Android初学习 - 调用startActivityForResult后,onActivityResult为什么立刻响应