Appium+Pytest+Allure集成PO项目管理模式实现自动化测试
Appium+Pytest+Allure集成PO项目管理模式实现自动化测试
- 环境配置
- Appium环境配置
- Pytest环境配置
- Allure环境配置
- 使用与集成
- Appium使用
- Pytest使用
- Allure使用
- PO项目管理模式
环境配置
前提条件: Java+Android SDK+ADB+Python
Appium环境配置
- Appium配置:
Appium客户端下载地址:http://appium.io/
运⾏appium-desktop-Setup-1.2.7.exe,默认安装即可
启动客户端,按图⽚步骤 1 -> 2 -> 3 -> 4 设置
启动成功展示如下图
Pytest环境配置
- Pytest配置:
cmd输入pip3 install pytest==3.8.0下载pytest包
2.常用插件配置
下载pytest自带测试报告插件
cmd输入 pip3 install pytest-html下载pytest控制函数执行顺序插件
cmd输入 pip3 install pytest-ordering下载pytest失败重试插件
cmd输入 pip3 install pytest-rerunfailures==3.0
3.cmd输入python --version检测pytest版本是否安装成功
如下图
Allure环境配置
1.allure与pytest集成是在pytest中用一个插件
pip3 install pytest-allure-adaptor 用于生成XML测试报告
如果上面的包报错就删除上面的包使用下面这个
allure-pytest 2.6.1
2.allure环境变量的配置
1.解压allure2.6.0.zip到英⽂路径
2.进⼊步骤1的bin⽬录 :复制当前bin⽬录的路径 假设为X
3.进⼊电脑的环境变量,path系统环境变量,追加步骤2bin⽬录的路径
4.如果你的电脑已经打开了dos命令,那么关闭后,在启动dos命令,输⼊allure 回⻋
使用与集成
Appium使用
1.连接设备必要代码
# server 启动参数
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
# 声明driver对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
2.Appium元素API
元素API | 语法 | 使用方法 |
---|---|---|
id定位 | find_element_by_id(id_value) | driver.find_element_by_id(“com.android.settings:id/search”).click() |
class定位 | find_element_by_class_name(class_value) | driver.find_element_by_class_name(‘android.widget.ImageButton’).click() |
Xpath定位 | find_element_by_xpath(xpath_value) | driver.find_element_by_xpath("//*[contains(@text,‘WLA’)]").click() |
Xpath常用属性定位
1. id ://[contains(@resource-id,‘com.android.settings:id/search’)]
2. class : //[contains(@class,‘android.widget.ImageButton’)]
3. text : //*[contains(@text,‘WLA’)]
API | 语法 | 使用方法 |
---|---|---|
swip滑动 | wipe(start_x, start_y, end_x, end_y, duration=None) | driver.swipe(188,659,148,248) |
scroll滑动事件scroll | (origin_el, destination_el) | driver.scroll(el1,el2) |
drag拖拽事件 | drag_and_drop(origin_el, destination_el) | driver.drag_and_drop(el1,el2) |
应⽤置于后台事件 | background_app(seconds) | driver.background_app(5) |
Pytest使用
1.代码示例
import pytest
class Test_ABC:def setup_class(self):#类级优先执行print("------->setup_class")def teardown_class(self):#类级最后执行print("------->teardown_class")def setup(self):#函数级级优先执行print("------->setup")def teardown(self):#函数级最后执行print("------->teardown")@pytest.mark.run(order=1)#第一个执行的用例def test_a(self):print("------->test_a")assert 1@pytest.mark.run(order=2)#第二个执行的用例def test_b(self):print("------->test_b")assert 0#执行顺序#setup_class()-->setup()-->test_a()-->test_b()-->teardown()-->teardown_class()
if __name__ == '__main__':pytest.main("-s test_ABC.py")
2.打印日志
E:\Study\Python\Appium\Appium_Pytest_Allure>pytest f.py
============================= test session starts =============================
platform win32 -- Python 3.6.8, pytest-3.8.0, py-1.8.0, pluggy-0.12.0
rootdir: E:\Study\Python\Appium\Appium_Pytest_Allure, inifile:
plugins: allure-adaptor-1.7.10, html-1.21.1, metadata-1.8.0, ordering-0.6, rerunfailures-3.0
collected 2 items f.py .. [100%]========================== 2 passed in 0.05 seconds ===========================
3.Pytest配置文件
[pytest]
# command line
addopts = -s --reruns 2 --alluredir report
# search path
testpaths = ./Script
# search file
python_files = Test*
# search classes
python_classes = Test*
# search function
python_functions = test*
Allure使用
1.在ini配置文件中加入报告
addopts = --alluredir report
2.执行完用例后执行生成html报告
控制台或cmd输入allure generate ./report -o ./html
3.在报告中添加测试步骤
@allure.step(title=“测试步骤名称”) # 标记于测试⽅法上⽅
4.allure添加步骤具体描述信息
allure.attach(“标题”, “具体描述内容”) # 标题是⽣成txt⽂件, txt⽂件内写⼊具体描述内容
5.allure添加测试⽤例严重级别
@pytest.allure.severity(severity)
#severity
1.pytest.allure.severity_level.BLOCKER # 最严重
2.pytest.allure.severity_level.CRITICAL # 相对严重
3.pytest.allure.severity_level.NORMAL # ⼀般的问题
4.pytest.allure.severity_level.MINOR # 较⼩的问题
5.pytest.allure.severity_level.TRIVIAL # 可以忽略的问题
6.allure添加测试截图
allure.attach(“图⽚名字”, “读取图⽚数据”, “指定图⽚类型”)
将⼀张png图⽚添加到测试报告:
with open(“图⽚路径”, “rb”) as f:
allure.attach(“截图”, f.read(), allure.attach_type.PNG)
7.allure覆盖已⽣成测试报告
allure generate 报告⽂件夹 -o ./html --clean
–clean: 覆盖已⽣成的html报告
PO项目管理模式
1.整理思路
2.项目结构
App_Project # 项⽬名称
Basic# 存储基础设施类
------->init.py # 空⽂件
------->Init_Driver.py # ⼿机驱动对象初始化
------->Base.py # ⽅法的⼆次封装
------->read_data.py #数据解析读取⽅法
Page # 存储封装⻚⾯⽂件
------->init.py # 存储⻚⾯元素
------->earch_page.py # 封装⻚⾯元素的操作⽅法
Data # 存储数据⽂件
------->search_data.yaml(也可以是其他⽂件⽐如txt,excel,json,数据库等)
Test # 存储测试脚本⽬录
------->test_search.py # 测试搜索⽂件
Inint_Dritver.py
def init_driver():#服务端启动参数desired_caps={}## ⼿机系统信息desired_caps['platformName']='Android'desired_caps['platformVersion']='9'##设备号desired_caps['deviceName']='19021'##包名desired_caps['appPackage']='com.android.settings'##启动名desired_caps['appActivity']='.SettingsActivity'desired_caps['noReset']=True##允许输⼊中⽂# desired_caps['unicodeKeyboard']=True# desired_caps['resetKeyboard']=True##⼿机驱动对象driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)return driver
Base.py
from selenium.webdriver.support.wait import WebDriverWaitclass Base(object):def __init__(self,driver):self.driver=driverdef find_element(self,loc,timeout=1):print('第二步')return WebDriverWait(self.driver,timeout).until(lambda x: x.find_element(*loc))def click_element(self,loc):self.find_element(loc).click()def input_text(self,loc,text):self.fm=self.find_element(loc)self.fm.clear()self.fm.send_keys(text)
search_page.py
import timefrom Basic.Base import Base
import Pageclass Search_Page(Base):def __init__(self,driver):Base.__init__(self,driver)def input_search_text(self):self.click_element(Page.search_button) # 传⼊的__init__.py⽂件声明的search_button
test_search.py
from Page.search_page import Search_Page
from Basic.Init_Driver import init_driver
import time
class Test_Base:def __init__(self):self.driver=init_driver()def test(self):time.sleep(2)sp=Search_Page(self.driver)time.sleep(1)sp.input_search_text()print('第四步')# self.driver.quit()
Appium+Pytest+Allure集成PO项目管理模式实现自动化测试相关推荐
- CSDN绝无仅有只此一篇:Appium+pytest+allure+jenkins如何实现多台手机连接详细教程教学
使用appium可以实现app自动化测试,我们之前是连接一台手机去运行, 如何同时连接多台手机呢? 很多人可能想到的是多线程(threading). 今天分享一种比多线程更简单的方法,虽然不是多台手机 ...
- UiAutomator2+Pytest+Allure+PO模型实现Android自动化测试
介绍 uiautomator2 是一个可以使用Python对Android设备进行UI自动化的库.其底层基于Google uiautomator,Google提供的uiautomator库可以获取屏幕 ...
- Pytest框架集成Allure定制测试报告详解(一)
Allure简介 Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架. 它支持绝大多数测试框架, 例如TestNG.Pytest.JUint等.它简单易用,易于集成.下面就Pytest如何 ...
- jenkins 插件目录_Windows下allure+pytest+jenkins集成手册!
Pytest是什么 pytest是python的一款测试框架,拥有unittest的功能并比它更丰富. Allure是什么 有非常多的优秀的测试框架,但却是有非常少优秀的报告工具可以展示非常清楚的用例 ...
- Selenium4+Pytest+Allure+PO自动化测试框架最新设计
最新设计说明: 使用selenium4的以服务方式连接驱动,使用 selenium4唯一的两种定位方式,并加上智能流畅等待的封装. 最终效果:1.实现页面代码与测试 代码分离,2.封装公共方法,其他页 ...
- 基于Appium+Pytest的UI自动化实例(Android)
基于Python3 Appium+Pytest的UI自动化实例(Android) 春有百花秋有月,夏有凉风冬有雪 若无闲事挂心头,便是人间好时节 第一部分:所需环境的配置 所需软件网盘链接(提取码19 ...
- 接口自动化测试框架开发 | Pytest+Allure+AIOHTTP+用例自动生成
测试开发实战技能进阶学习,文末加群! 近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西. 接口测试是比较讲究效率的,测试人员会希望很快能得到结果反馈,然而 ...
- python pytest和allure环境_【转载】Python—Pytest+Allure定制报告
Allure Test Report 一款测试报告框架,不仅报告美观,而且方便CI集成. 一.环境配置 安装Python依赖库: pip3 install pytest pip3 install py ...
- pytest allure测试报告_Appium+pytest+allure+jenkins如何实现多台手机连接
很多人可能想到的是多线程(threading). 今天分享一种比多线程更简单的方法,虽然不是多台手机同时运行,但可以连接多台手机依次运行. 大致的运行方式是:001号测试用例:A手机,B手机...,0 ...
最新文章
- 卧槽,又一个Java面试神器!!!
- CSS图形每日一练(下)
- Silverlight+WCF 实战-网络象棋最终篇之对战视频-上篇[客户端开启视频/注册编号/接收视频](五)...
- 《算法》练习题1.1.1--1.1.39 答案解析
- CSS边框,背景,边距,溢出
- 区块链和比特币的 6 个神话:揭穿了这项技术的有效性
- 四款主流测试工具的测试流程
- Visual Studio 2005中的Windows Mobile模拟器
- Visio中如何绘制斜线箭头
- 《HTTP权威指南》读书笔记(1)-HTTP简介与消息结构
- 基于STM32的红外万能遥控器完整教程
- 5G无线技术基础自学系列 | 5G NR和LTE信道结构比较
- 2014年Q1-Q3国内创业生态报告:在技术革命的部署阶段,泡沫不是问题
- Clear Type之父谈阅读革命(转载)
- FBE 与FDE学习总结
- Python+Vue计算机毕业设计报刊征订管理系统uu609(源码+程序+LW+部署)
- Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2) C.Alternating Sum(等比数列求和)
- 计算机专业买苹果笔记本哪款好,2019苹果笔记本电脑哪款好,MacBook Pro值得买吗?...
- 唯品会定时任务组件Saturn的时间不一致bug,超时
- Hive Show命令