复刻QIMEI UUID42并默认使用无头浏览器

This commit is contained in:
yml2213
2026-09-02 16:59:46 +08:00
parent c62c025ced
commit 17ee943753
9 changed files with 205 additions and 41 deletions
+53
View File
@@ -0,0 +1,53 @@
from pathlib import Path
from core.huya import browser_harvest
class _FakeStderr:
def readline(self):
return "DevTools listening on ws://127.0.0.1/devtools/browser/test\n"
class _FakeProcess:
stderr = _FakeStderr()
def kill(self):
pass
def test_launch_defaults_to_headless(monkeypatch):
calls = []
def fake_popen(args, **kwargs):
calls.append((args, kwargs))
return _FakeProcess()
def no_http(*args, **kwargs):
raise OSError("test: no CDP endpoint")
monkeypatch.setattr(browser_harvest.subprocess, "Popen", fake_popen)
monkeypatch.setattr(browser_harvest.urllib.request, "urlopen", no_http)
browser_harvest.launch(Path("/tmp/test-huya-profile"), 9555)
args, kwargs = calls[0]
assert "--headless=new" in args
assert kwargs["stdout"] is browser_harvest.subprocess.DEVNULL
def test_launch_can_show_window_when_requested(monkeypatch):
calls = []
def fake_popen(args, **kwargs):
calls.append(args)
return _FakeProcess()
def no_http(*args, **kwargs):
raise OSError("test: no CDP endpoint")
monkeypatch.setattr(browser_harvest.subprocess, "Popen", fake_popen)
monkeypatch.setattr(browser_harvest.urllib.request, "urlopen", no_http)
browser_harvest.launch(Path("/tmp/test-huya-profile"), 9556, headless=False)
assert "--headless=new" not in calls[0]