修改了上传页面点击的逻辑;增加循环
This commit is contained in:
113
main.py
113
main.py
@@ -163,32 +163,99 @@ class DeviceAutomation(object):
|
||||
EC.element_to_be_clickable((AppiumBy.ID, "com.bjjw.cjgc:id/img_2_layout"))
|
||||
)
|
||||
upload_page_btn.click()
|
||||
upload_page_btn.click()
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
# 遍历断点列表,逐个执行上传操作
|
||||
upload_success_count = 0
|
||||
for breakpoint_name in global_variable.get_upload_breakpoint_list():
|
||||
try:
|
||||
logging.info(f"设备 {self.device_id} 开始处理断点 '{breakpoint_name}' 的上传")
|
||||
upload_success_count = 0 # 上传成功的断点数量
|
||||
# 实现连续获取断点列表直到两次相同
|
||||
previous_breakpoint_list = None
|
||||
current_breakpoint_list = None
|
||||
max_attempts = 10 # 最大尝试次数
|
||||
attempt_count = 0
|
||||
while True:
|
||||
# 获取当前页面的断点列表
|
||||
|
||||
# 从当前页面获取断点列表名称
|
||||
current_breakpoint_list = self.upload_config_page.get_breakpoint_list_from_page()
|
||||
attempt_count += 1
|
||||
if current_breakpoint_list is None:
|
||||
logging.warning(f"设备 {self.device_id} 没有获取到断点列表,结束上传流程")
|
||||
break
|
||||
|
||||
logging.info(f"第 {attempt_count} 次获取断点列表: {current_breakpoint_list}")
|
||||
|
||||
# 检查是否与上一次获取的列表相同
|
||||
if previous_breakpoint_list is not None and current_breakpoint_list == previous_breakpoint_list:
|
||||
logging.info("连续两次获取到相同的断点列表,结束上传")
|
||||
# 下滑一次再次检查是否一致
|
||||
# 获取列表容器
|
||||
list_container = self.driver.find_element(AppiumBy.ID, "com.bjjw.cjgc:id/upload_result_list")
|
||||
|
||||
# 安全地获取断点信息
|
||||
line_num = global_variable.get_upload_breakpoint_dict().get(breakpoint_name)
|
||||
if line_num is None:
|
||||
logging.warning(f"设备 {self.device_id} 断点 '{breakpoint_name}' 在字典中未找到,跳过上传")
|
||||
continue
|
||||
if not line_num:
|
||||
logging.warning(f"设备 {self.device_id} 断点 '{breakpoint_name}' 未获取到line_num,跳过上传")
|
||||
continue
|
||||
|
||||
# 执行上传配置管理,传入当前断点名称
|
||||
if self.upload_config_page.upload_config_page_manager(self.results_dir, breakpoint_name, line_num):
|
||||
logging.info(f"设备 {self.device_id} 断点 '{breakpoint_name}' 上传成功")
|
||||
upload_success_count += 1
|
||||
else:
|
||||
logging.error(f"设备 {self.device_id} 断点 '{breakpoint_name}' 上传失败")
|
||||
# 计算滑动坐标
|
||||
start_x = list_container.location['x'] + list_container.size['width'] // 2
|
||||
# 向下滑动
|
||||
start_y = list_container.location['y'] + list_container.size['height'] * 0.95
|
||||
end_y = list_container.location['y'] + list_container.size['height'] * 0.05
|
||||
logging.info("向下滑动列表")
|
||||
self.driver.swipe(start_x, start_y, start_x, end_y, 500)
|
||||
current_breakpoint_list = self.upload_config_page.get_breakpoint_list_from_page()
|
||||
if previous_breakpoint_list is not None and current_breakpoint_list == previous_breakpoint_list:
|
||||
break
|
||||
|
||||
previous_breakpoint_list = current_breakpoint_list.copy() if current_breakpoint_list else None
|
||||
# 遍历当前页面列表,逐个执行上传操作
|
||||
|
||||
for breakpoint_name in current_breakpoint_list:
|
||||
|
||||
# # 遍历断点列表,逐个执行上传操作
|
||||
# upload_success_count = 0
|
||||
# for breakpoint_name in global_variable.get_upload_breakpoint_list():
|
||||
try:
|
||||
# 检查断点名称是否在当前页面列表中
|
||||
if breakpoint_name not in current_breakpoint_list:
|
||||
logging.warning(f"设备 {self.device_id} 断点 '{breakpoint_name}' 不在当前页面列表中,跳过上传")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"设备 {self.device_id} 处理断点 '{breakpoint_name}' 时发生异常: {str(e)}")
|
||||
logging.info(f"设备 {self.device_id} 开始处理断点 '{breakpoint_name}' 的上传")
|
||||
|
||||
# 安全地获取断点信息
|
||||
# breakpoint_names = global_variable.get_upload_breakpoint_dict()
|
||||
# logging.info(f"设备 {self.device_id} 断点字典 '{breakpoint_names}' 中包含断点 '{breakpoint_name}'")
|
||||
ui_breakpoint_dict = {}
|
||||
for key, value in global_variable.get_upload_breakpoint_dict().items():
|
||||
# 去掉末尾的"-平原"
|
||||
if key.endswith('-平原'):
|
||||
ui_key = key[:-3] # 去掉最后3个字符"-平原"
|
||||
else:
|
||||
ui_key = key
|
||||
ui_breakpoint_dict[ui_key] = value
|
||||
|
||||
line_num = ui_breakpoint_dict.get(breakpoint_name)
|
||||
logging.info(f"设备 {self.device_id} 断点 '{breakpoint_name}' 对应的line_num为 {line_num}")
|
||||
|
||||
if line_num is None:
|
||||
logging.warning(f"设备 {self.device_id} 断点 '{breakpoint_name}' 在字典中未找到,跳过上传")
|
||||
continue
|
||||
if not line_num:
|
||||
logging.warning(f"设备 {self.device_id} 断点 '{breakpoint_name}' 未获取到line_num,跳过上传")
|
||||
continue
|
||||
|
||||
# 执行上传配置管理,传入当前断点名称
|
||||
if self.upload_config_page.upload_config_page_manager(self.results_dir, breakpoint_name, line_num):
|
||||
logging.info(f"设备 {self.device_id} 断点 '{breakpoint_name}' 上传成功")
|
||||
upload_success_count += 1
|
||||
else:
|
||||
logging.error(f"设备 {self.device_id} 断点 '{breakpoint_name}' 上传失败")
|
||||
for i in range(3):
|
||||
if self.upload_config_page.upload_config_page_manager(self.results_dir, breakpoint_name, line_num):
|
||||
logging.info(f"设备 {self.device_id} 断点 '{breakpoint_name}' 重试上传成功")
|
||||
upload_success_count += 1
|
||||
break
|
||||
else:
|
||||
logging.error(f"设备 {self.device_id} 断点 '{breakpoint_name}' 上传失败,第 {i+1} 次重试")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"设备 {self.device_id} 处理断点 '{breakpoint_name}' 时发生异常: {str(e)}")
|
||||
|
||||
logging.info(f"设备 {self.device_id} 上传配置管理执行完成,成功上传 {upload_success_count}/{len(global_variable.get_upload_breakpoint_list())} 个断点")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user