50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
# 返利浏览器适配:共享类、Chrome junction、端口差异。
|
||
|
||
from __future__ import annotations
|
||
|
||
from apa_browser_adapter import (
|
||
ApaBrowserAdapter,
|
||
REPO_ROOT,
|
||
chrome_debug_port,
|
||
chrome_session_flow,
|
||
resolve_chrome_profile_dir,
|
||
use_user_chrome,
|
||
)
|
||
|
||
|
||
# 返利 ApaBrowserAdapter 是 rpa_browser 共享类或其子类。
|
||
def test_adapter_is_shared_or_subclass():
|
||
from rpa_browser.adapter import ApaBrowserAdapter as Shared
|
||
|
||
assert issubclass(ApaBrowserAdapter, Shared)
|
||
|
||
|
||
# REBATE_HEADER / IMPORT / SUBMIT 复用查号同一 profile 和调试口。
|
||
def test_rebate_nodes_share_find_chrome_session(monkeypatch):
|
||
monkeypatch.delenv("RPA_USE_USER_CHROME", raising=False)
|
||
monkeypatch.delenv("RPA_CHROME_DEBUG_PORT", raising=False)
|
||
assert chrome_session_flow("REBATE_HEADER") == "REBATE_FIND"
|
||
assert chrome_session_flow("REBATE_IMPORT") == "REBATE_FIND"
|
||
assert chrome_session_flow("REBATE_SUBMIT") == "REBATE_FIND"
|
||
assert resolve_chrome_profile_dir("REBATE_HEADER") == resolve_chrome_profile_dir("REBATE_FIND")
|
||
assert chrome_debug_port("REBATE_HEADER") == chrome_debug_port("REBATE_FIND")
|
||
assert chrome_debug_port("REBATE_FIND") == 9335
|
||
|
||
|
||
# RPA_USE_USER_CHROME 打开时调试口固定 9222,不跟班次口走。
|
||
def test_user_chrome_debug_port_is_9222(monkeypatch):
|
||
monkeypatch.setenv("RPA_USE_USER_CHROME", "1")
|
||
monkeypatch.delenv("RPA_CHROME_DEBUG_PORT", raising=False)
|
||
assert use_user_chrome() is True
|
||
assert chrome_debug_port("REBATE_FIND") == 9222
|
||
assert chrome_debug_port("REBATE_HEADER") == 9222
|
||
|
||
|
||
# 用户 Chrome 的 profile 是仓库外 daily-chrome junction,不要 resolve 回默认 User Data。
|
||
def test_user_chrome_profile_is_daily_chrome_junction(monkeypatch):
|
||
monkeypatch.setenv("RPA_USE_USER_CHROME", "1")
|
||
monkeypatch.setattr("apa_browser_adapter._ensure_user_chrome_junction", lambda link, real: None)
|
||
path = resolve_chrome_profile_dir("REBATE_FIND")
|
||
assert path == REPO_ROOT.parent / "rpa-chrome-profile" / "daily-chrome"
|
||
assert path.name == "daily-chrome"
|