appium自动化测试(4)部分方法&unitest初步使用
2024-10-19 10:55:46
捕捉弹窗 https://github.com/appium/appium/issues/968完整有截屏的例子:https://github.com/bitbar/testdroid-samples/blob/master/appium/sample-scripts/python/testdroid_android_hybrid.py有详细解释的例子:http://www.cnblogs.com/fnng/p/3300788.html
1、unittest
2、截屏并保存driver.save_screenshot("F:/testSpace/unittest0/1.png")
2、setUpClass方法实现,一次性设置3、中文编码:文件头添加 #coding:utf-8
完整登陆&退出用例:
#coding:utf-8
## XX_login_logout_testcase
import unittest
import time
from appium import webdriver
classLoginTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
print("------------------setUp Test-----------------------")
desired_caps ={}
desired_caps['platformName']='Android'
desired_caps['platformVersion']='4.4.4'
desired_caps['deviceName']='Android Emulator'
desired_caps['appPackage']='com.XX.activity'
desired_caps['appActivity']='.AppStartActivity'
desired_caps['unicodeKeyboard']=True
desired_caps['resetKeyboard']=True
cls.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
@classmethod
def tearDownClass(cls):
cls.driver.close_app()
cls.driver.quit()
print("-------------------- Byebye ----------------------- ")
def setUp(self):
print("setup")
def tearDown(self):
print("teardown")
def test1_log_in(self):
time.sleep(5)
# wait for the log advertise
self.driver.find_element_by_name(u"我的").click()
self.driver.find_element_by_id('com.XX.activity:id/tv_userheadloginfail_login').click()# 点击登陆
# log by phone number and password
self.driver.find_element_by_id('com.XX.activity:id/mobile_login').click()
self.driver.find_element_by_id('android:id/text1').click()
self.driver.find_element_by_id('com.XX.activity:id/edt_mobilenum').send_keys("13580478329")
self.driver.find_element_by_id('com.XX.activity:id/edt_password').send_keys("1234567")
self.driver.find_element_by_id('com.XX.activity:id/login').click()
time.sleep(5)
self.driver.save_screenshot("F:/testSpace/loginTestCase1/src/loginByPhoneNumber.png")
print("login ok")
def test2_log_out(self):
# log out
self.driver.find_element_by_name(u"我的").click()
self.driver.find_element_by_id('com.XX.activity:id/rl_usercontent_setting').click()
self.driver.find_element_by_id('com.XX.activity:id/exit').click()
time.sleep(2)
self.driver.find_element_by_id('android:id/button2').click()
time.sleep(5)
self.driver.save_screenshot("F:/testSpace/loginTestCase1/src/logout.png")
print("log out ok")
print("Test2 ok")
if __name__ =='__name__':
unittest.main()
附件列表
最新文章
- [erl] erlang 进程注册和注销
- OD使用教程4
- shopex商城的部署和安装
- motto4
- oracle group by中cube和rollup字句的使用方法及区别
- cocos2d-x 扩充引擎基类功能 引起的头文件重复包含问题的分析
- zoj3658 Simple Function (函数值域)
- Eclipse RCP /Plugin移除Search对话框
- 温故知新 javascript 正则表达式
- curl: (48) An unknown option was passed in to libcurl怎么解决
- MP4文件格式
- python-day33--进程间通信(IPC)
- tomcat 启动超级慢
- KHFlatButton
- ot
- Loader拉取图片,由于redirect重定向,导致策略文件无效 设置checkPolicyFile后还是无效:需要一个策略文件,但在加载此媒体时未设置 checkPolicyFile 标志
- [转]C/C++作用域详解
- Linux:LAMP搭建DISCU!论坛
- ThinkJS 中的Logic层
- sense之间的数据传输