标签:用例 发送 青春 dcs start web arm implicit ui自动化
app流程和生成报告:
案例1:
from appium import webdriver
from time import *
import unittest
from shouji.HTMLTestRunner3_New import HTMLTestRunner
class TestApp(unittest.TestCase):
def setUp(self):
self.desired_caps={
‘platformName‘:‘Android‘, #平台系统:Android or Ios
‘deviceName‘:‘SM-G9350‘, #设备名称
‘platformVersion‘:‘android-4.4W‘, #平台版本
‘appPackage‘:‘com.baidu.yuedu‘, #包名
‘appActivity‘:‘com.baidu.yuedu.splash.SplashActivity‘, #activity
‘unicodeKeyboard‘: True, #使用unicode编码方式发送字符串 }
‘resetKeyboard‘:True} #是将键盘隐藏起来
self.driver=webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,self.desired_caps)
def tearDown(self):
sleep(4)
self.driver.quit()
def test001(self):
self.driver.find_element_by_id("com.baidu.yuedu:id/negativeUpgrade").click()
sleep(5)
self.driver.find_element_by_id("com.baidu.yuedu:id/righttitle").click()
sleep(5)
self.driver.find_element_by_xpath(‘//android.widget.TextView[@text="免费"]‘).click()
sleep(5)
self.driver.find_element_by_xpath("//android.view.View[@content-desc=‘更多 Link‘]").click()
sleep(5)
self.driver.find_element_by_xpath("//android.view.View[@index=‘2‘]").click()
sleep(5)
self.driver.find_element_by_id("com.baidu.yuedu:id/book_add_cart").click()
sleep(5)
self.driver.find_element_by_id("com.baidu.yuedu:id/ball").click()
if __name__ == ‘__main__‘:
path=r"F:\untitled\untitled5\shouji"
discover = unittest.TestLoader().discover(start_dir=path, pattern=‘appzdh.py‘)
dir=r‘F:\untitled\untitled5\shouji‘ + ‘\\‘ + ‘ui.html‘
filename=open(dir, ‘wb‘)
runner = HTMLTestRunner(stream=filename,
title=‘UI自动化测试报告‘,
description=‘用例执行情况如下‘,
tester=‘dcs‘)
案例2:
import unittest
from time import sleep
from shoujiapp.HTMLTestRunner3_New import HTMLTestRunner
from appium import webdriver
from shoujiapp.cc import * #滑动屏幕的模块
desired_caps={
‘platformName‘:‘Android‘, #平台系统:Android or Ios
‘deviceName‘:‘SM-G9350‘, #设备名称
‘platformVersion‘:‘android-4.4W‘, #平台版本
‘appPackage‘:‘com.baidu.yuedu‘, #包名
‘appActivity‘:‘com.baidu.yuedu.splash.SplashActivity‘, #activity
‘unicodeKeyboard‘: True, #使用unicode编码方式发送字符串
‘resetKeyboard‘:True #是将键盘隐藏起来
}
class Test_baiduyuedu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps) # remote(请求方式)4723看appium
self.driver.implicitly_wait(20) # 隐式等待20秒
sleep(3)
self.driver.find_element_by_xpath(‘//android.widget.TextView[@text="取消"]‘).click()
sleep(3)
def tearDown(self):
sleep(3)
self.driver.quit() #释放资源,关闭app
# 第一条自动化测试用例 购买小说
def test01(self):
self.driver.find_element_by_name("图书").click()
sleep(3)
# self.driver.find_element_by_name("免费").click()
# sleep(3)
# self.driver.find_element_by_name(‘我路过青春,却错过你 叶冰伦 ¥6.99‘).click()
# sleep(3)
# self.driver.find_element_by_id(‘com.baidu.yuedu:id/cart_bg‘).click()
# sleep(3)
# self.driver.find_element_by_id(‘com.baidu.yuedu:id/cart_buy_confirm‘).click()
# sleep(3)
# self.driver.find_element_by_id(‘com.baidu.yuedu:id/phone_number_input‘).send_keys(‘15757163397‘)
# self.driver.find_element_by_name(‘获取验证码‘).click()
# 第二条自动化测试用例 滑动屏幕
# def test02(self):
# self.driver.find_element_by_name("图书").click()
# sleep(2)
# rollUp(self.driver, 2) #向上 2次
# sleep(2)
# rollDown(self.driver, 2) #向下
# sleep(2)
# rollLeft(self.driver, 2) #向左
# sleep(2)
# rollRight(self.driver, 2) #向右
# 第四种执行用例方法===》自动搜索+生成测试报告
if __name__ == ‘__main__‘:
path = r‘D:\PyCharm 2017.2.3\untitled\shoujiapp‘
discover = unittest.TestLoader().discover(start_dir=path, pattern=‘自*.py‘)
dir = r‘D:\PyCharm 2017.2.3\untitled\shoujiapp‘+‘\\‘+‘zidong.html‘
filename = open(dir,‘wb‘) #以二进制的方法写入文件内容
runner = HTMLTestRunner(stream=filename,
title=‘UI自动化测试报告‘,
description=‘用例执行情况如下‘,
tester=‘dcs‘)
runner.run(discover)
肖sir_多测师 _高级讲师 第二个月21讲解app测试之案例定位和生成报告
标签:用例 发送 青春 dcs start web arm implicit ui自动化
原文地址:https://www.cnblogs.com/xiaolehua/p/14444521.html