# SelniumPOM **Repository Path**: yunmengliM7/SelniumPOM ## Basic Information - **Project Name**: SelniumPOM - **Description**: 用Pytest fixture来实现一个用例 一个driver对象,充分满足pytest-xdist的分布式要求,实际项目中应该可以更多分层,此为学习记录 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 7 - **Forks**: 3 - **Created**: 2021-07-25 - **Last Updated**: 2025-08-27 ## Categories & Tags **Categories**: testing **Tags**: None ## README # 简介 > selenium POM Pytest 结合,通过Pytest fixture 来传递Driver 保证一个测试用例[1] :driver[1] 学习记录 # 插件包 [selenium](https://selenium-python-zh.readthedocs.io/en/latest/api.html): 操作浏览器 [pytest](https://docs.pytest.org/en/stable/): drvier传递,收集/执行测试用例 [pytest-xdist](https://pypi.org/project/pytest-xdist/): 分布式执行测试用例 [pytest-html](https://github.com/pytest-dev/pytest-xdist): 收集测试结果-测试报告 [webdriver_manager](https://github.com/SergeyPirogov/webdriver_manager): 浏览器驱动管理,它会自动去下载合适的浏览器Driver # 测试资源 被测应用: [博客后台](https://gitee.com/zy7y/blog/tree/drf-blog/) > 其实是一个只有DRF 个人博客实现的后台,用的就是Django Admin 原生后台 1. 下载/克隆: `git clone -b drf-blog https://gitee.com/zy7y/blog.git` 2. 本地启动: ```shell 1. python -m venv venv # 创建虚拟环境 2. venv\Scripts\activate # windows 启动虚拟环境 3. pip install -r requirements.txt # 安装依赖包 4. Django项目配置 1. python manage.py makemigrations blog 2. python manage.py migrate 3. python manage.py createsuperuser --email admin@example.com --username admin 4. python manage.py runserver ``` 浏览器版本: Google Chrome 版本 92.0.4515.107 # 目录结构 **目录结构生成: `tree /f`** ```shell ├─Config # 配置文件 │ │ __init__.py │ └─ config.py │ ├─Pages # 页面对象 │ │ __init__.py │ │ BasePage.py │ │ HomePage.py │ └─ LoginPage.py │ ├─Reports # 测试报告 │ └─ report.html │ │ └─Tests # 测试文件 │ │ __init__.py │ │ conftest.py │ │ test_base.py │ │ test_home.py │ └─ test_login.py │ .gitignore # git 忽略文件 │ main.py # 启动文件 │ pytest.ini # pytest配置文件 │ readme.md # 项目说明 └─ requirements.txt # 依赖库 ``` # 使用 1. `git clone [repo]` 2. `python -m venv venv` 3. 激活venv: `venv\Scripts\activate` 4. 运行: 执行pytest 或者 运行main.py 文件