yj
2024-07-24 3b84cce1ee43215b9f398148fda19f4b1025856b
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
41
42
43
44
45
46
47
48
"""
    测试数据共享文件
"""
 
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"
    # 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:
    """
    读取测试使用的数据
    :param request: 接收传递的参数
    :return: 字典
    """
    # 获取当前项目根路径
    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(file_path, "r", encoding="utf-8") as f:
        values = json.load(f)
        return values[key]