使用python写appium用例
2015-08-08 12:19
197 查看
安装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
微信公众帐号:
wirelessqa
关于作者:
作者: 毕小朋 | 老 毕 邮箱: wirelessqa.me@gmail.com微博: @WirelessQA 博客: http://blog.csdn.net/wirelessqa
相关文章推荐
- android 设置布局动画
- Unity3D中uGUI事件系统简述及使用方法总结
- android-----ANR
- [Android Studio 权威教程]AS 中配置强大的版本管理系统(Git、SVN、等)
- [Android Studio 权威教程]AS构建系统-Gradle
- iOS中获取文件路径的几种方法
- [Android Studio 权威教程]断点调试和高级调试
- 设备模型之kobject,kset及其关系
- [Android Studio 权威教程]AS添加第三方库的6种方式(Jar,module,so等)
- [Android Studio 权威教程]最实用的快捷键
- [Android Studio 权威教程]Android Studio 三种添加插件的方式
- [Android Studio 权威教程]配置出“NB”的Android Studio
- [Android Studio 权威教程]离线配置SDK,创建第一个AS项目
- [Android Studio 权威教程]Windows下安装Android Studio
- [Android Studio 权威教程]Mac下安装Android Studio
- swift 广播
- android 当不点击的时候不会出现键盘,点击后出现键盘
- iOS 一个ViewController上显示2个tableView的方法
- adb停止工作解决
- 【hibernate mapping 详解】….hbm.xml配置