""" 测试数据共享文件 """ 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(scope="session") def driver(request): options = Options() options.debugger_address = "127.0.0.1:9222" # 初始化webdriver driver = webdriver.Chrome(options=options) request.addfinalizer(driver.quit) return driver @pytest.fixture(scope="session") def data_read(request) -> dict: """ 读取测试使用的数据 :param request: 接收传递的参数 :return: 字典 """ # 获取当前项目根路径 root_path = os.getcwd() if "\\testcase" in root_path: root_path = root_path[0:root_path.rfind("\\testcase")] # 获取到要获取数据的键 key = request.param # 读取数据 with open(root_path + r"\data\test_data.json", "r", encoding="utf-8") as f: values = json.load(f) return values[key]