待补平差检查和上传逻辑

This commit is contained in:
2026-05-26 14:40:04 +08:00
parent 19afa3d19b
commit 10db652cbc
18 changed files with 217 additions and 29 deletions

View File

@@ -17,8 +17,12 @@ from urllib3.connection import port_by_scheme
def run_command(command):
"""执行系统命令并返回输出"""
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout.strip()
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, encoding='utf-8', errors='ignore')
return result.stdout.strip()
except Exception:
result = subprocess.run(command, shell=True, capture_output=True, text=True, errors='ignore')
return result.stdout.strip()
# =======================
@@ -131,18 +135,39 @@ def cleanup_wireless_connections(target_device_ip=None, target_port=4723):
def start_appium():
appium_port = 4723
print(f"🚀 启动 Appium Server端口 {appium_port}...")
subprocess.Popen(
["appium.cmd", "-a", "127.0.0.1", "-p", str(appium_port)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
# 检查端口是否就绪替代固定sleep
# 先检查端口是否已被占用
try:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(("127.0.0.1", appium_port))
sock.close()
if result == 0:
print(f"✅ Appium Server 已在运行(端口 {appium_port}")
return True
except Exception:
pass
# 启动 Appium Server
try:
subprocess.Popen(
["appium.cmd", "-a", "127.0.0.1", "-p", str(appium_port)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
except FileNotFoundError:
print("❌ 未找到 appium.cmd请确认 Appium 已正确安装")
return False
except Exception as e:
print(f"❌ Appium Server 启动失败: {str(e)}")
return False
# 检查端口是否就绪
max_wait = 30 # 最大等待30秒
start_time = time.time()
while time.time() - start_time < max_wait:
try:
# 尝试连接Appium端口验证是否就绪
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(("127.0.0.1", appium_port))
@@ -190,7 +215,7 @@ def setup_adb_wireless():
if not usb_devices:
print("❌ 未检测到 USB 设备")
return
return None
for serial in usb_devices:
print(f"\n🔎 处理设备: {serial}")
@@ -261,7 +286,10 @@ def setup_adb_wireless():
# print("🔄 关闭Appium连接...")
# driver.quit()
break # 处理完第一个设备后退出,如需处理多个设备可移除此行
return wireless_id # 返回无线连接的设备ID
print("❌ 未能成功建立无线连接")
return None
# =======================