使用python写appium用例
Python 用例 Appium 使用
2023-09-27 14:27:02 时间
安装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
版权声明:本文博客原创文章,博客,未经同意,不得转载。
相关文章
- python基础练习 报时助手
- [ python ] 练习作业 - 3
- 11月4日科技资讯|罗永浩回应被列老赖;三星解散自研 CPU 团队;Python 采用 12 个月的发布周期 | 极客头条
- Python面试题目之Python的复制和赋值浅析
- Linux下使用python脚本获取本机CPU,内存,网络使用状态的方法
- Python编程:Django入门及常见错误
- python pyenv
- Python 集合(set)类型的操作——并交差
- 【Python】程序的组织结构:顺序结构
- ImportError: cannot import name ‘get_config‘ from ‘tensorflow.python.eager.context‘
- 使用Python、OpenCV翻转图像(水平、垂直、水平垂直翻转)
- 成功解决:Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python pytest测试框架介绍七 ---测试用例显示用例注释名称
- python nose测试框架全面介绍十四 --- nose中的只跑上次失败用例
- python nose 自写插件打乱class类中用例执行顺序,但将test_a和test_z排除
- python nose 自写插件支持用例带进度
- python nose测试框架全面介绍十---用例的跳过
- PyQt(Python+Qt)学习随笔:QWidget部件的palette属性以及ColorGroup、colorRole的用途和含义
- PyQt(Python+Qt)学习随笔:QAbstractItemView的autoScroll和autoScrollMargin属性
- PyQt(Python+Qt)学习随笔:Qt Designer中部件mimimumSize和maximumSize的含义
- 第8.26节 重写Python类中的__getattribute__方法实现实例属性访问捕获
- python中_new_()与_init_()的区别
- 爱剪辑加字幕之经验及Python程序批量加字幕
- 批量将python打包成.so文件(python将py编译成so)