appium自动化测试部分方法&unitest初步使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了appium自动化测试部分方法&unitest初步使用相关的知识,希望对你有一定的参考价值。
捕捉弹窗 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()
附件列表
以上是关于appium自动化测试部分方法&unitest初步使用的主要内容,如果未能解决你的问题,请参考以下文章
Appium学习笔记——Appium初探,下载与安装以及初步的录制尝试