All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 32s
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""stealth 启动参数与开关测试。"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import unittest
|
|
|
|
from jiangchang_skill_core.rpa.stealth import (
|
|
persistent_context_launch_parts,
|
|
stealth_enabled,
|
|
)
|
|
|
|
|
|
class TestStealth(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self._saved = os.environ.get("OPENCLAW_PLAYWRIGHT_STEALTH")
|
|
|
|
def tearDown(self) -> None:
|
|
if self._saved is None:
|
|
os.environ.pop("OPENCLAW_PLAYWRIGHT_STEALTH", None)
|
|
else:
|
|
os.environ["OPENCLAW_PLAYWRIGHT_STEALTH"] = self._saved
|
|
|
|
def test_stealth_enabled_default_on(self) -> None:
|
|
os.environ.pop("OPENCLAW_PLAYWRIGHT_STEALTH", None)
|
|
self.assertTrue(stealth_enabled())
|
|
|
|
def test_stealth_enabled_off_values(self) -> None:
|
|
for off in ("0", "false", "no", "off", "FALSE"):
|
|
os.environ["OPENCLAW_PLAYWRIGHT_STEALTH"] = off
|
|
self.assertFalse(stealth_enabled(), msg=off)
|
|
|
|
def test_launch_parts_stealth_on(self) -> None:
|
|
os.environ["OPENCLAW_PLAYWRIGHT_STEALTH"] = "1"
|
|
args, ignore = persistent_context_launch_parts()
|
|
self.assertIn("--start-maximized", args)
|
|
self.assertIn("--disable-blink-features=AutomationControlled", args)
|
|
self.assertEqual(ignore, ["--enable-automation"])
|
|
|
|
def test_launch_parts_stealth_off(self) -> None:
|
|
os.environ["OPENCLAW_PLAYWRIGHT_STEALTH"] = "0"
|
|
args, ignore = persistent_context_launch_parts()
|
|
self.assertIn("--start-maximized", args)
|
|
self.assertNotIn("--disable-blink-features=AutomationControlled", args)
|
|
self.assertIsNone(ignore)
|
|
|
|
def test_launch_parts_extra_args(self) -> None:
|
|
os.environ["OPENCLAW_PLAYWRIGHT_STEALTH"] = "1"
|
|
args, _ = persistent_context_launch_parts(extra_args=["--foo"])
|
|
self.assertIn("--foo", args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|