# playwright-master **Repository Path**: casual123/playwright-master ## Basic Information - **Project Name**: playwright-master - **Description**: 基于pytest+playwright的自动化测试框架 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 0 - **Created**: 2023-08-17 - **Last Updated**: 2024-09-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # playwright-master > 基于 playwright 和 pytest 单元测试框架的自动化项目 ### 实现功能 * 使用python3 -m playwright codegen进行录制,自动生成代码脚本,直接复制到test_cases中使用 * 将登录前置到conftest.py中,避免执行每个用例都登录一次 * 日志记录运行情况 * pytest-html查看测试结果 ### 安装依赖库 ```shell $ 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` 文件配置 ```python 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" ``` ### 运行 运行测试 ```shell $ python run.py ```