![]() |
||
---|---|---|
.idea | ||
element | ||
test_cases | ||
test_report/20230816-171151 | ||
tools | ||
.gitignore | ||
README.md | ||
conftest.py | ||
requirements.txt | ||
run.py |
README.md
playwright-master
基于 playwright 和 pytest 单元测试框架的自动化项目
实现功能
- 使用python3 -m playwright codegen进行录制,自动生成代码脚本,直接复制到test_cases中使用
- 将登录前置到conftest.py中,避免执行每个用例都登录一次
- 日志记录运行情况
- pytest-html查看测试结果
安装依赖库
$ pip install -r requirements.txt
依赖库
playwright==1.36.0
pytest-playwright==0.4.2
pytest==7.4.0
pytest-html==3.2.0
pytest-rerunfailures==10.2
seldom==3.2.3
注:安装requirements.txt
指定依赖库的版本,这是经过测试的,有时候新的版本可会有错。
配置
在 config.py
文件配置
class RunConfig:
"""
运行测试配置
"""
# 运行测试用例的目录或文件
cases_path = "test_cases/test_001.py"
# 配置浏览器驱动类型(chromium, firefox, webkit)。
browser = "chromium"
# 运行模式(headless, headful)
mode = "headful"
# 配置运行的 URL
url = "https://www.baidu.com"
# 失败重跑次数
rerun = "0"
# 当达到最大失败数,停止执行
max_fail = "5"
运行
运行测试
$ python run.py