阳洁
2023-07-28 ddf66cf155af3805323ec55ae6814f2d23d40c07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
    测试数据共享文件
"""
 
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]