-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
41 lines (41 loc) · 1.22 KB
/
conftest.py
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
# import pytest
# from playwright.sync_api import sync_playwright
#
# @pytest.fixture(scope="session")
#
# def pytest_addoption(parser):
# """
# 添加命令行选项 --cn-jwt,用于传递 JWT Token。
# """
# parser.addoption(
# "--cn-jwt",
# action="store",
# default=None,
# help="JWT Token for authentication",
# )
# def browser_context(pytestconfig):
# """
# 初始化 Playwright 浏览器上下文,并设置通用的 JWT Token 和 localStorage。
# """
# # Access configuration options using pytestconfig
# jwt_token = pytestconfig.getoption("--cn-jwt")
# if not jwt_token:
# raise ValueError("--cn-jwt option is required but not provided")
#
# # 启动 Playwright
# playwright = sync_playwright().start()
# browser = playwright.chromium.launch(headless=False)
# context = browser.new_context()
#
# # 设置 localStorage
# context.add_init_script(f"""
# localStorage.setItem('coScene_org_jwt', '{jwt_token}');
# localStorage.setItem('i18nextLng', 'cn');
# """)
#
# # 返回上下文供测试用例使用
# yield context
#
# # 测试结束后清理资源
# context.close()
# browser.close()