簡介

selenium POM Pytest 結合,通過Pytest fixture 來傳遞Driver 保證一個測試用例[1] :driver[1] 學習記錄

外掛包

selenium: 操作瀏覽器

pytest: drvier傳遞,收集/執行測試用例

pytest-xdist: 分散式執行測試用例

pytest-html: 收集測試結果-測試報告

webdriver_manager: 瀏覽器驅動管理,它會自動去下載合適的瀏覽器Driver

測試資源

被測應用: 部落格後臺

其實是一個只有DRF 個人部落格實現的後臺,用的就是Django Admin 原生後臺

  1. 下載/克隆: git clone -b drf-blog https://gitee.com/zy7y/blog.git
  2. 本地啟動:
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 [email protected] --username admin 4. python manage.py runserver

瀏覽器版本: Google Chrome 版本 92.0.4515.107

目錄結構

目錄結構生成: tree /f

├─Config    # 配置檔案
│ │ __init__.py
│ └─ config.py

├─Pages # 頁面物件
│ │ __init__.py
│ │ BasePage.py
│ │ HomePage.py
│ └─ LoginPage.py

├─Reports # 測試報告
│ │ report.html
│ │
│ └─ assets
│ style.css

└─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 https://gitee.com/zy7y/SelniumPOM
  2. python -m venv venv
  3. 啟用venv: venv\Scripts\activate
  4. 執行: 執行pytest 或者 執行main.py 檔案