2 Commits
2 changed files with 30 additions and 3 deletions
+8 -1
View File
@@ -139,7 +139,14 @@ class TaskRunner(threading.Thread):
self._set_current(phase='打开页面', detail=self.url)
self._log(f'打开页面: {self.url}')
browser.open(self.url, timeout=60)
browser.wait('--load', 'networkidle', timeout=45)
# 等待页面加载:优先 networkidle;若页面依赖的外部 CDN 挂起导致
# networkidle 永不满足,降级为等待 load 事件 + 短暂缓冲,不阻断测试
try:
browser.wait('--load', 'networkidle', timeout=20)
except BrowserError:
self._log('networkidle 超时(可能外部 CDN 慢),降级等待 load 事件')
browser.wait('--load', 'load', timeout=30)
time.sleep(2)
self._log('页面已打开')
self._set_current(phase='页面已打开')
+22 -2
View File
@@ -3,6 +3,7 @@
import json
import os
import subprocess
import time
from config import AGENT_BROWSER, NODE_BIN_DIR, XDG_RUNTIME_DIR
@@ -43,8 +44,27 @@ class AgentBrowser:
pass
return out
def open(self, url, timeout=60):
return self._run(['open', url], timeout=timeout, check=True)
# 瞬时网络故障(服务重启/端口切换等)会自动重试的错误特征
RETRYABLE_ERRS = (
'ERR_EMPTY_RESPONSE', 'ERR_CONNECTION_REFUSED',
'ERR_CONNECTION_RESET', 'ERR_CONNECTION_CLOSED',
'ERR_TIMED_OUT', 'ERR_NAME_NOT_RESOLVED', 'ERR_SOCKET_NOT_CONNECTED',
'ERR_ADDRESS_UNREACHABLE', 'ERR_NETWORK_CHANGED', 'ERR_INTERNET_DISCONNECTED',
)
def open(self, url, timeout=60, retries=2):
"""打开页面;对瞬时连接类错误自动重试(默认最多重试 2 次,间隔 2s/4s)"""
last_err = None
for attempt in range(retries + 1):
try:
return self._run(['open', url], timeout=timeout, check=True)
except BrowserError as e:
last_err = e
if attempt < retries and any(t in str(e) for t in self.RETRYABLE_ERRS):
time.sleep(2 * (attempt + 1))
continue
raise
raise last_err
def snapshot(self, interactive=True, compact=False, depth=None, timeout=60):
args = ['snapshot']