添加重试

This commit is contained in:
2026-03-14 17:53:14 +08:00
parent b80f553009
commit 19afa3d19b
7 changed files with 37 additions and 3 deletions

Binary file not shown.

View File

@@ -122,6 +122,16 @@ class DeviceAutomation:
def init_driver(self): def init_driver(self):
"""初始化Appium驱动""" """初始化Appium驱动"""
try: try:
try:
if not driver_utils.check_session_valid(self.driver, self.device_id):
logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver)
if not self.driver:
logging.error(f"设备 {self.device_id} 驱动重连失败")
return False
except Exception as inner_e:
logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}")
return False
# # 使用全局函数初始化驱动 # # 使用全局函数初始化驱动
# self.driver, self.wait = driver_utils.init_appium_driver(self.device_id) # self.driver, self.wait = driver_utils.init_appium_driver(self.device_id)
# 初始化页面对象 # 初始化页面对象

View File

@@ -34,6 +34,17 @@ class CheckStation:
# # 确保Appium服务器正在运行,不在运行则启动 # # 确保Appium服务器正在运行,不在运行则启动
# if not driver_utils.check_server_status(4723): # if not driver_utils.check_server_status(4723):
# driver_utils.start_appium_server() # driver_utils.start_appium_server()
try:
if not driver_utils.check_session_valid(self.driver, self.device_id):
logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver)
if not self.driver:
logging.error(f"设备 {self.device_id} 驱动重连失败")
return False
except Exception as inner_e:
logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}")
return False
# 检查应用是否成功启动 # 检查应用是否成功启动
if driver_utils.is_app_launched(self.driver): if driver_utils.is_app_launched(self.driver):
@@ -82,6 +93,17 @@ class CheckStation:
# return True # return True
def add_transition_point(self): def add_transition_point(self):
"""添加转点""" """添加转点"""
try:
if not driver_utils.check_session_valid(self.driver, self.device_id):
logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver)
if not self.driver:
logging.error(f"设备 {self.device_id} 驱动重连失败")
return False
except Exception as inner_e:
logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}")
return False
try: try:
# 查找并点击添加转点按钮 # 查找并点击添加转点按钮
add_transition_btn = self.wait.until( add_transition_btn = self.wait.until(

View File

@@ -12,6 +12,7 @@ import globals.driver_utils as driver_utils
import actions import actions
import check_station import check_station
from check_station import get_excel_from_url from check_station import get_excel_from_url
import globals.create_link as create_link
PORT = "COM9" PORT = "COM9"
BAUD = 115200 BAUD = 115200
@@ -24,6 +25,7 @@ RESPONSE_PAYLOAD = {
def main() -> int: def main() -> int:
create_link.setup_adb_wireless()
driver, wait, device_id = DriverManager.get_driver() driver, wait, device_id = DriverManager.get_driver()
url = f"https://database.yuxindazhineng.com/team-bucket/69378c5b4f42d83d9504560d/前测点表/20260309/CDWZQ-2标-龙家沟左线大桥-0-11号墩-平原.xlsx" url = f"https://database.yuxindazhineng.com/team-bucket/69378c5b4f42d83d9504560d/前测点表/20260309/CDWZQ-2标-龙家沟左线大桥-0-11号墩-平原.xlsx"
station_data = get_excel_from_url(url) station_data = get_excel_from_url(url)
@@ -49,7 +51,7 @@ def main() -> int:
# station等于0时启动actions.py # station等于0时启动actions.py
if station_value == 0: if station_value == 0:
print("\n🚀 站点编号为0启动 actions.py") print("🚀 站点编号为0启动 actions.py\n")
# 启动 actions.py # 启动 actions.py
app = actions.DeviceAutomation(driver=driver, wait=wait, device_id=device_id) app = actions.DeviceAutomation(driver=driver, wait=wait, device_id=device_id)
app.run_automation() app.run_automation()
@@ -57,7 +59,7 @@ def main() -> int:
# station大于0时启动check_station.py # station大于0时启动check_station.py
elif station_value > 0 and over_station_num < station_quantity and station_value not in over_station_list: elif station_value > 0 and over_station_num < station_quantity and station_value not in over_station_list:
print(f"\n🚀 站点编号为{station_value},启动 check_station.py") print(f"🚀 站点编号为{station_value},启动 check_station.py\n")
# 启动 check_station.py # 启动 check_station.py
# driver_utils.ensure_appium_server_running() # driver_utils.ensure_appium_server_running()
app = check_station.CheckStation(driver, wait, device_id) app = check_station.CheckStation(driver, wait, device_id)

View File

@@ -122,7 +122,7 @@ def init_appium_driver(device_id, app_package="com.bjjw.cjgc", app_activity=".ac
options.automation_name = "UiAutomator2" options.automation_name = "UiAutomator2"
options.no_reset = True options.no_reset = True
options.auto_grant_permissions = True options.auto_grant_permissions = True
options.new_command_timeout = 28800 options.new_command_timeout = 3600
options.udid = device_id options.udid = device_id
# 增加uiautomator2服务器启动超时时间 # 增加uiautomator2服务器启动超时时间