当前位置:网站首页>APP自动化测试-Appium进阶
APP自动化测试-Appium进阶
2022-06-23 03:55:00 【balahalalala】
App自动化测试(学习笔记三)——Appium进阶
Appium进阶
触屏操作
TouchActions官方地址
appium2.0+ 触屏操作方法:待补充
appium官网文档
模拟来电
self.driver.make_gsm_call(‘5551234567’, GsmCallActions.CALL)
模拟来短信
self.driver.send_sms(‘555-123-4567’, ‘Hey lol’)
模拟网络切换
self.driver.set_network_connection(1)
截图
self.driver.get_screenshot_as_file(‘./photos/img.png’)
录屏
self.driver.start_recording_screen()
…
self.driver.stop_recording_screen()
自动化关键数据记录
- 行为日志
使用 python 自带的 logging 模块
使用 pytest.ini 配置日志开关与格式
pytest.ini 文件配置日志级别,保存地址等内容。
注意:windows系统 需要把中文 注释去掉。
[pytest]
;日志开关 true false
log_cli = true
;日志级别
log_cli_level = info
;打印详细日志,相当于命令行加 -vs
addopts = --capture=no
;日志格式
log_cli_format = %(asctime)s [%(levelname)s] %(message)s (%(filename)s:%(lineno)s)
;日志时间格式
log_cli_date_format = %Y-%m-%d %H:%M:%S
;日志文件位置
log_file = ./log/test.log
;日志文件等级
log_file_level = info
;日志文件格式
log_file_format = %(asctime)s [%(levelname)s] %(message)s (%(filename)s:%(lineno)s)
;日志文件日期格式
log_file_date_format = %Y-%m-%d %H:%M:%S
import codecs
def ReadFile(filePath, encoding="utf-8"):
with codecs.open(filePath, "r", encoding) as f:
return f.read()
def WriteFile(filePath, u, encoding="gbk"):
with codecs.open(filePath, "w", encoding) as f:
f.write(u)
def UTF8_2_GBK(src, dst):
content = ReadFile(src, encoding="utf-8")
WriteFile(dst, content, encoding="gbk")
UTF8_2_GBK('pytest_utf8.ini', 'pytest.ini')
- 截图
| 方法名 | 描述 |
|---|---|
| get_screenshot_as_file(filename) | 保存图片为.png 格式,filename 图片路径 |
| save_screenshot(filename) | 保存图片为.png 格式,filename 图片路径 |
| get_screenshot_as_png() | 保存图片为二进制格式 |
| get_screenshot_as_base64() | 将图片保存为 base64 格式。通常用在 html 里添加截图 |
- 页面源码
通过获取页面源码,分析页面的 dom 结构
driver.page_source
打印当前页面为xml
print(self.driver.page_source)
自动化测试实战
思路:
- 梳理测试用例:梳理用例流程、前置后置
- 构造po模型:创建页面相关的类和方法
- 编写测试用例:根据业务逻辑编写、链式调用
- 填充具体实现:实现的时候BasePage进行封装
- 优化用例:封装样板代码、提取页面元素、添加起始页面的url。。
PO 模型类图,分为三层:
- 具体业务层
- 公共业务层
- 和业务无关的公共方法层

app 弹窗异常处理
运行过程中不定时弹框:广告、升级提示、短信、、、、弹框不是bug
try:
find
except:
处理异常逻辑
异常逻辑:黑名单机制,遍历黑名单,如果发现黑名单弹框,则点掉,继续执行find方法;如果达到最大查找次数,还是异常,则抛出NoSuchException错误信息。
装饰器
对原有函数的功能增强
不改变原有函数的逻辑
使代码更简洁、易维护
测试框架
打造测试框架的需求与价值
领域模型适配:封装业务实现,实现业务管理
提高效率:降低用例维护成本,提高执行效率
增强功能:解决已有框架不满足的情况
自动化框架应具备的功能
支持管理用例,运行用例
支持查找元素/定位元素,对元素/页面 进行各种操作(点击,滑动,输入等等)
支持生成测试报告
能够实现功能的复用,(比如登录,搜索等)
当页面有异常弹框的时候,可以进行有效的处理
当用例失败,需要添加失败时的日志,截图,等信息,放在测试报告中
多设备并发
支持平台化
…
自动化测试框架实现
| 功能 | 实现 |
|---|---|
| 管理用例,运行用例 | pytest |
| 查找元素/定位元素 | Appium |
| 测试报告 | Allure |
| 功能复用 | PO 实现 |
| 异常弹框 | 编写代码 |
| 失败时的日志,截图 | 编写代码 |
| 多设备并发 | selenium grid |
| 平台化 | VUE+FLASK/Django |
项目结构

为什么要封装框架?复用*平台化*
增强功能
异常处理(弹窗黑名单)
日志记录\运行日志记录\错误日志记录
报告生成:
异常日志
异常截图
测试用例步骤
测试描述
bug,issue 关联
用例分类(feature,story,step 等)
pip install allure-pytest
pytest test_xxx.py --alluredir=./result
allure serve ./result
- 参数化与数据驱动:
支持支持测试用例 / 步骤层级的参数化驱动配置
配置方式包括三个部分
参数定义(指定名字)
数据源指定(指定 yaml 文件 /或者其它格式文件)
数据源准备(无论是从线上环境 捞的数据,还是自己创建的测试数据)
减少冗余代码\集中管理测试数据\便于维护
- 总结
自动化测试框架应具备的功能
自动化测试框架优化(在 PO 的基础上,添加异常处理,日志,报告 ,截图,参数化与数据驱动等)逐步的将框架完善
边栏推荐
- 架构师之路,从「存储选型」起步
- Image noise reduction denoise AI
- Missing essential plugin
- UnityShader入门精要——Unity中的渲染优化技术(四)
- Hard core, become a high-quality tester: learn to communicate with products
- Complete the primary school project in 3 days, and teach you to complete the weather broadcast system hand in hand!
- Servlet self study notes
- 网上有真实的兼职吗?大学生怎么找暑期兼职?
- Cookie-Session讲解
- HCIP 作业 BGP总结
猜你喜欢

Rtklib new version 2.4.3 B34 test comparison

树莓派网络远程访问

Difficult to find a job in a bad environment? Ali on three sides. Fortunately, he has made full preparations and has offered

JSP entry notes

gis利器之Gdal(三)gdb数据读取

应用挂了~

Beyond chips and AI, why is hard technology capital becoming more and more "hard core"?

BGP second test

I have been engaged in software testing for 5 years and have changed jobs for 3 times. I have understood the field of software testing

② Cocoapods principle and podspec file uploading operation
随机推荐
vmware网络连接出错Unit network.service not found
AMS:startActivity桌面启动应用
BGP summary of hcip operation
Laravel8 implementation of picture verification code
JDBC调用存储过程、MySQL触发器
Implementation of the rotation chart
百度飞桨“万有引力”2022首站落地苏州,全面启动中小企业赋能计划
Learn to draw Er graph in an article
Architecture à trois niveaux MVC
直接插入排序——【常见排序法(1/8)】
985 test engineer is hanged. Who is more important in terms of education and experience?
Penetration test basis | attached test points and test scenarios
组合式API-composition-api
8 years' experience: monthly salary of 3000 to 30000, the change of Test Engineer
Missing essential plugin
Three tier architecture experiment
Web application security testing guide
JDBC call stored procedure, MySQL trigger
经济发展由新技术推动着来
Drag and drop拖放框架