结合测量仪测试完毕,准备测平差+上传

This commit is contained in:
2026-06-06 10:18:32 +08:00
parent 2a1ba2e76a
commit c7ebac49a0
9 changed files with 335 additions and 219 deletions

View File

@@ -11,6 +11,8 @@ import globals.driver_utils as driver_utils # 导入驱动工具模块
from selenium.common.exceptions import TimeoutException, NoSuchElementException, StaleElementReferenceException
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import globals.ids as ids
@@ -200,7 +202,7 @@ class CheckStation:
logging.info("检查站点成功")
return True
def run(self, station_num: int):
def run(self):
# last_station_num = 0
url = f"https://database.yuxindazhineng.com/team-bucket/69378c5b4f42d83d9504560d/前测点表/20260309/CDWZQ-2标-龙家沟左线大桥-0-11号墩-平原.xlsx"
@@ -258,32 +260,35 @@ class CheckStation:
print(f"已处理{over_station_num}个站点")
# 滑动列表到底部
if not self.scroll_list_to_bottom(device_id):
logging.error(f"设备 {device_id} 下滑列表到底部失败")
if not self.scroll_list_to_bottom(self.device_id):
logging.error(f"设备 {self.device_id} 下滑列表到底部失败")
return False
# 2. 点击最后一个spinner
if not self.click_last_spinner_with_retry(device_id):
logging.error(f"设备 {device_id} 点击最后一个spinner失败")
if not self.click_last_spinner_with_retry(self.device_id):
logging.error(f"设备 {self.device_id} 点击最后一个spinner失败")
return False
# 3. 再下滑一次
if not self.scroll_down_once(device_id):
logging.warning(f"设备 {device_id} 再次下滑失败,但继续执行")
if not self.scroll_down_once(self.device_id):
logging.warning(f"设备 {self.device_id} 再次下滑失败,但继续执行")
# # 截图
# self.driver.save_screenshot("check_station.png")
if not self.take_screenshot():
logging.error(f"设备 {device_id} 截图失败")
logging.error(f"设备 {self.device_id} 截图失败")
# 打完数据,截图完毕,点击平差处理按钮
if not self.click_adjustment_button(device_id):
logging.error(f"设备 {device_id} 点击平差处理按钮失败")
if not self.click_adjustment_button(self.device_id):
logging.error(f"设备 {self.device_id} 点击平差处理按钮失败")
return False
item = global_variable.GLOBAL_CURRENT_PROJECT_NAME
if item.endswith('-平原'):
item = item[:-3] # 去掉最后3个字符"-平原"
# 检查是否在测量页面在就重新执行选择断点滑动列表到底部点击最后一个spinner 再下滑一次,点击平差处理按钮平差
if not self.handle_back_navigation(item, device_id):
if not self.handle_back_navigation(item, self.device_id):
logging.error(f"{item}平差失败")
@@ -293,11 +298,14 @@ class CheckStation:
# 检查在不在测量列表页面,不在就点击返回按钮并处理弹窗
if self.check_measurement_list(device_id):
logging.error(f"设备 {device_id} 未在测量列表页面")
if self.check_measurement_list(self.device_id):
logging.error(f"设备 {self.device_id} 未在测量列表页面")
# 点击返回按钮并处理弹窗
if not self.execute_back_navigation_steps(device_id):
logging.error(f"设备 {device_id} 处理返回按钮确认失败")
if not self.execute_back_navigation_steps(self.device_id):
logging.error(f"设备 {self.device_id} 处理返回按钮确认失败")
# # 点击返回按钮并处理弹窗
# if not self.execute_back_navigation_steps(self.device_id):
# logging.error(f"设备 {self.device_id} 处理返回按钮确认失败")
return True
@@ -467,15 +475,15 @@ class CheckStation:
"""查找指定关键词并点击,支持向下和向上滑动查找"""
try:
# if not check_session_valid(self.driver, self.device_id):
# self.logger.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
# logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
# if not reconnect_driver(self.device_id, self.driver):
# self.logger.error(f"设备 {self.device_id} 驱动重连失败")
# logging.error(f"设备 {self.device_id} 驱动重连失败")
# 等待线路列表容器出现
self.wait.until(
EC.presence_of_element_located((AppiumBy.ID, ids.MEASURE_LIST_ID))
)
self.logger.info("线路列表容器已找到")
logging.info("线路列表容器已找到")
max_scroll_attempts = 100 # 最大滚动尝试次数
scroll_count = 0
@@ -485,21 +493,21 @@ class CheckStation:
while scroll_count < max_scroll_attempts:
# 获取当前页面中的所有项目
current_items = self.get_current_items()
# self.logger.info(f"当前页面找到 {len(current_items)} 个项目: {current_items}")
logging.info(f"当前页面找到 {len(current_items)} 个项目: {current_items}")
# 检查目标文件是否在当前页面中
if fixed_filename in current_items:
self.logger.info(f"找到目标文件: {fixed_filename}")
logging.info(f"找到目标文件: {fixed_filename}")
# 点击目标文件
if self.click_item_by_text(fixed_filename):
return True
else:
self.logger.error(f"点击目标文件失败: {fixed_filename}")
logging.error(f"点击目标文件失败: {fixed_filename}")
return False
# 检查是否到达底部:连续两次获取的项目相同
if current_items == previous_items and len(current_items) > 0:
self.logger.info("连续两次获取的项目相同,已到达列表底部")
logging.info("连续两次获取的项目相同,已到达列表底部")
break
# 更新前一次项目集合
@@ -507,14 +515,14 @@ class CheckStation:
# 向下滑动列表以加载更多项目
if not self.scroll_list(direction="down"):
self.logger.error("向下滑动列表失败")
logging.error("向下滑动列表失败")
return False
scroll_count += 1
self.logger.info(f"{scroll_count} 次向下滑动,继续查找...")
logging.info(f"{scroll_count} 次向下滑动,继续查找...")
# 如果向下滑动未找到,尝试向上滑动查找
self.logger.info("向下滑动未找到目标,开始向上滑动查找")
logging.info("向下滑动未找到目标,开始向上滑动查找")
# 重置滚动计数
scroll_count = 0
@@ -524,38 +532,38 @@ class CheckStation:
# 如果返回False说明已经滑动到顶
if not self.scroll_list(direction="up"):
# 检查是否是因为滑动到顶而返回False
if "已滑动到列表顶部" in self.logger.handlers[0].buffer[-1].message:
self.logger.info("已滑动到列表顶部,停止向上滑动")
if "已滑动到列表顶部" in logging.handlers[0].buffer[-1].message:
logging.info("已滑动到列表顶部,停止向上滑动")
break
else:
self.logger.error("向上滑动列表失败")
logging.error("向上滑动列表失败")
return False
# 获取当前页面中的所有项目
current_items = self.get_current_items()
# self.logger.info(f"向上滑动后找到 {len(current_items)} 个项目: {current_items}")
# logging.info(f"向上滑动后找到 {len(current_items)} 个项目: {current_items}")
# 检查目标文件是否在当前页面中
if fixed_filename in current_items:
self.logger.info(f"找到目标文件: {fixed_filename}")
logging.info(f"找到目标文件: {fixed_filename}")
# 点击目标文件
if self.click_item_by_text(fixed_filename):
return True
else:
self.logger.error(f"点击目标文件失败: {fixed_filename}")
logging.error(f"点击目标文件失败: {fixed_filename}")
return False
scroll_count += 1
self.logger.info(f"{scroll_count} 次向上滑动,继续查找...")
logging.info(f"{scroll_count} 次向上滑动,继续查找...")
self.logger.warning(f"经过 {max_scroll_attempts * 2} 次滑动仍未找到目标文件")
logging.warning(f"经过 {max_scroll_attempts * 2} 次滑动仍未找到目标文件")
return False
except TimeoutException:
self.logger.error("等待线路列表元素超时")
logging.error("等待线路列表元素超时")
return False
except Exception as e:
self.logger.error(f"查找关键词时出错: {str(e)}")
logging.error(f"查找关键词时出错: {str(e)}")
return False
def get_current_items(self):
@@ -574,7 +582,7 @@ class CheckStation:
return item_texts
except Exception as e:
self.logger.error(f"获取当前项目失败: {str(e)}")
logging.error(f"获取当前项目失败: {str(e)}")
return []
def click_item_by_text(self, text):
@@ -588,35 +596,35 @@ class CheckStation:
title_element = item.find_element(AppiumBy.ID, ids.MEASURE_NAME_TEXT_ID)
if title_element and title_element.text == text:
title_element.click()
self.logger.info(f"已点击项目: {text}")
logging.info(f"已点击项目: {text}")
return True
except NoSuchElementException:
continue
self.logger.warning(f"未找到可点击的项目: {text}")
logging.warning(f"未找到可点击的项目: {text}")
return False
except Exception as e:
self.logger.error(f"点击项目失败: {str(e)}")
logging.error(f"点击项目失败: {str(e)}")
return False
def handle_measurement_dialog(self):
"""处理测量弹窗 - 选择继续测量"""
try:
self.logger.info("检查测量弹窗...")
logging.info("检查测量弹窗...")
# 直接尝试点击"继续测量"按钮
continue_btn = WebDriverWait(self.driver, 2).until(
EC.element_to_be_clickable((AppiumBy.ID, "com.bjjw.cjgc:id/measure_continue_btn"))
)
continue_btn.click()
self.logger.info("已点击'继续测量'按钮")
logging.info("已点击'继续测量'按钮")
return True
except TimeoutException:
self.logger.info("未找到继续测量按钮,可能没有弹窗")
logging.info("未找到继续测量按钮,可能没有弹窗")
return True # 没有弹窗也认为是成功的
except Exception as e:
self.logger.error(f"点击继续测量按钮时出错: {str(e)}")
logging.error(f"点击继续测量按钮时出错: {str(e)}")
return False
# 检查有没有平差处理按钮
@@ -629,13 +637,13 @@ class CheckStation:
if apply_btn.is_displayed():
logging.info("进入平差页面")
else:
self.logger.info("没有找到'平差处理'按钮")
logging.info("没有找到'平差处理'按钮")
return True
except TimeoutException:
self.logger.info("未找到平差处理按钮")
logging.info("未找到平差处理按钮")
return False # 没有弹窗也认为是成功的
except Exception as e:
self.logger.error(f"点击平差处理按钮时出错: {str(e)}")
logging.error(f"点击平差处理按钮时出错: {str(e)}")
return False
@@ -676,6 +684,68 @@ class CheckStation:
logging.error(f"设备 {device_id} 执行返回导航步骤时发生错误: {str(e)}")
return False
def click_back_button(self, device_id):
"""点击手机系统返回按钮"""
try:
self.driver.back()
logging.info("已点击手机系统返回按钮")
return True
except Exception as e:
logging.error(f"点击手机系统返回按钮失败: {str(e)}")
return False
def handle_confirmation_dialog(self, device_id, timeout=2):
"""
处理确认弹窗,点击""按钮
Args:
device_id: 设备ID
timeout: 等待弹窗的超时时间
Returns:
bool: 是否成功处理弹窗
"""
# 等待弹窗出现最多等待2秒
try:
max_attempts = 2
for attempt in range(max_attempts):
try:
dialog_message = WebDriverWait(self.driver, timeout).until(
EC.presence_of_element_located((AppiumBy.XPATH, "//android.widget.TextView[@text='是否退出测量界面?']"))
)
logging.info(f"设备 {device_id} 检测到确认弹窗 (第 {attempt + 1} 次)")
# 查找并点击"是"按钮
confirm_button = self.driver.find_element(
AppiumBy.XPATH,
"//android.widget.Button[@text='' and @resource-id='android:id/button1']"
)
if confirm_button.is_displayed() and confirm_button.is_enabled():
logging.info(f"设备 {device_id} 点击确认弹窗的''按钮 (第 {attempt + 1} 次)")
confirm_button.click()
time.sleep(0.5)
# 如果是第一次尝试,继续检查是否还有弹窗
if attempt < max_attempts - 1:
logging.info(f"设备 {device_id} 等待 1 秒后检查是否还有弹窗")
time.sleep(0.5)
continue
return True
else:
logging.error(f"设备 {device_id} ''按钮不可点击")
return False
except TimeoutException:
# 超时未找到弹窗,认为没有弹窗,返回成功
logging.info(f"设备 {device_id} 等待 {timeout} 秒未发现确认弹窗,可能没有弹窗,返回成功")
return True
except Exception as e:
logging.error(f"设备 {device_id} 处理确认弹窗时出错: {str(e)}")
return False
def scroll_list_to_bottom(self, device_id, max_swipes=60):
"""
@@ -806,7 +876,7 @@ class CheckStation:
# 使用self.device_id确保有默认值
actual_device_id = self.device_id if self.device_id else global_variable.get_device_id()
if not check_session_valid(self.driver, actual_device_id):
if not driver_utils.check_session_valid(self.driver, actual_device_id):
logging.warning(f"设备 {actual_device_id} 会话无效,尝试重新连接驱动...")
try:
# 使用正确的设备ID进行重连
@@ -860,7 +930,7 @@ class CheckStation:
logging.error(f"设备 {device_id} 等待下拉菜单超时 (第{retry_count+1}次尝试): {error_msg}")
# 检查是否是连接断开相关的错误
if not check_session_valid(self.driver, self.device_id):
if not driver_utils.check_session_valid(self.driver, self.device_id):
logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...")
# if any(keyword in error_msg for keyword in ['socket hang up', 'Could not proxy command']):
# logging.warning(f"设备 {device_id} 检测到连接相关错误,尝试重连...")