Go to file
casual ab94f0ca7a first commit 2023-08-17 14:55:39 +08:00
.idea first commit 2023-08-17 14:55:39 +08:00
element first commit 2023-08-17 14:55:39 +08:00
test_cases first commit 2023-08-17 14:55:39 +08:00
test_report/20230816-171151 first commit 2023-08-17 14:55:39 +08:00
tools first commit 2023-08-17 14:55:39 +08:00
.gitignore first commit 2023-08-17 14:55:39 +08:00
README.md first commit 2023-08-17 14:55:39 +08:00
conftest.py first commit 2023-08-17 14:55:39 +08:00
requirements.txt first commit 2023-08-17 14:55:39 +08:00
run.py first commit 2023-08-17 14:55:39 +08:00

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