| | |
| | | import pytest |
| | | import json |
| | | import os |
| | | from selenium import webdriver |
| | | from selenium.webdriver.chrome.options import Options |
| | | from selenium.webdriver.chrome.service import Service |
| | | from webdriver_manager.chrome import ChromeDriverManager |
| | | |
| | | |
| | | @pytest.fixture |
| | | @pytest.fixture(scope="session") |
| | | def driver(request): |
| | | options = Options() |
| | | # options.debugger_address = "127.0.0.1:9222" |
| | | options.add_argument('--headless') |
| | | options.add_argument('--no-sandbox') |
| | | options.add_argument('--disable-gpu') |
| | | options.add_argument('--disable-dev-shm-usage') |
| | | # options.add_argument('window-size=1200x600') |
| | | # 初始化webdriver |
| | | driver = webdriver.Chrome(options=options) |
| | | request.addfinalizer(driver.quit) |
| | | return driver |
| | | |
| | | |
| | | @pytest.fixture(scope="session") |
| | | def data_read(request) -> dict: |
| | | """ |
| | | 读取测试使用的数据 |
| | |
| | | """ |
| | | # 获取当前项目根路径 |
| | | root_path = os.getcwd() |
| | | print(root_path) |
| | | if "testcase" in root_path: |
| | | root_path = root_path.replace('testcase', '') |
| | | # 获取到要获取数据的键 |
| | | key = request.param |
| | | file_path = os.path.join(root_path, "data", "test_data.json") |
| | | print("file_path:", file_path) |
| | | # 读取数据 |
| | | with open(root_path + r"\data\test_data.json", "r", encoding="utf-8") as f: |
| | | with open(file_path, "r", encoding="utf-8") as f: |
| | | values = json.load(f) |
| | | return values[key] |