修改了上传页面点击的逻辑;增加循环
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -56,7 +56,7 @@ class ScreenshotPage:
|
||||
self.logger.info("向上滑动列表")
|
||||
|
||||
# 执行滑动
|
||||
self.driver.swipe(start_x, start_y, start_x, end_y, 1000)
|
||||
self.driver.swipe(start_x, start_y, start_x, end_y, 500)
|
||||
|
||||
|
||||
# 向上滑动时,检查是否滑动到顶
|
||||
@@ -1342,27 +1342,31 @@ class ScreenshotPage:
|
||||
retry_count += 1
|
||||
continue
|
||||
|
||||
# 点击返回按钮并处理弹窗
|
||||
if not self.execute_back_navigation_steps(device_id):
|
||||
self.logger.error(f"设备 {device_id} 处理返回按钮确认失败")
|
||||
retry_count += 1
|
||||
continue
|
||||
# 检查在不在测量列表页面,不在就点击返回按钮并处理弹窗
|
||||
if self.check_measurement_list(device_id):
|
||||
self.logger.error(f"设备 {device_id} 未在测量列表页面")
|
||||
# 点击返回按钮并处理弹窗
|
||||
if not self.execute_back_navigation_steps(device_id):
|
||||
self.logger.error(f"设备 {device_id} 处理返回按钮确认失败")
|
||||
retry_count += 1
|
||||
continue
|
||||
|
||||
# 成功处理完一个断点,添加到已处理列表
|
||||
processed_breakpoints.append(item)
|
||||
# add_breakpoint_to_upload_list(item, line_code)
|
||||
self.logger.info(f"成功处理断点: {item}")
|
||||
break # 跳出重试循环
|
||||
|
||||
# 检查是否重试次数用完仍未成功
|
||||
if retry_count >= max_retry_attempts:
|
||||
if retry_count == max_retry_attempts-1:
|
||||
self.logger.error(f"断点 {item} 经过 {max_retry_attempts} 次重试后仍然失败")
|
||||
|
||||
# 重新获取当前页面项目,因为可能有新的项目加载
|
||||
break
|
||||
continue
|
||||
# 向下滑动列表以加载更多项目
|
||||
if not self.scroll_list(direction="down"):
|
||||
self.logger.error("向下滑动列表失败")
|
||||
break
|
||||
continue
|
||||
|
||||
# 检查是否到达底部:连续两次获取的项目相同
|
||||
if current_items == previous_items and len(current_items) > 0:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# \page_objects\test_upload_config_page.py
|
||||
from appium.webdriver.common.appiumby import AppiumBy
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
||||
import logging
|
||||
@@ -24,6 +25,69 @@ class UploadConfigPage:
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.more_download_page = MoreDownloadPage(driver, wait,device_id)
|
||||
self.device_id = device_id
|
||||
|
||||
|
||||
def get_breakpoint_list_from_page(self):
|
||||
"""
|
||||
从当前页面获取断点列表的断点名称
|
||||
Returns:
|
||||
list: 断点名称列表
|
||||
"""
|
||||
breakpoint_list = []
|
||||
try:
|
||||
# 优化点1: 等待列表容器出现,确保页面已加载
|
||||
self.wait.until(EC.presence_of_element_located((By.ID, "com.bjjw.cjgc:id/upload_result_list")))
|
||||
|
||||
# 优化点2: 等待至少一个itemContainer出现,确保列表有数据
|
||||
self.wait.until(EC.presence_of_element_located((By.ID, "com.bjjw.cjgc:id/itemContainer")))
|
||||
|
||||
# 方法1: 直接获取所有标题元素(最直接高效)
|
||||
title_elements = self.driver.find_elements(By.ID, "com.bjjw.cjgc:id/title")
|
||||
|
||||
if title_elements:
|
||||
for element in title_elements:
|
||||
breakpoint_name = element.text
|
||||
if breakpoint_name and breakpoint_name.strip(): # 增加空值过滤
|
||||
breakpoint_list.append(breakpoint_name.strip())
|
||||
print(f"✅ 直接通过title获取到 {len(breakpoint_list)} 个断点")
|
||||
|
||||
# 方法2: 如果方法1失败,通过itemContainer获取(备选方案)
|
||||
if not breakpoint_list:
|
||||
print("⚠️ 直接获取title失败,尝试通过itemContainer获取...")
|
||||
item_containers = self.driver.find_elements(By.ID, "com.bjjw.cjgc:id/itemContainer")
|
||||
for container in item_containers:
|
||||
try:
|
||||
title_element = container.find_element(By.ID, "com.bjjw.cjgc:id/title")
|
||||
breakpoint_name = title_element.text
|
||||
if breakpoint_name and breakpoint_name.strip():
|
||||
breakpoint_list.append(breakpoint_name.strip())
|
||||
except:
|
||||
continue
|
||||
print(f"✅ 通过itemContainer获取到 {len(breakpoint_list)} 个断点")
|
||||
|
||||
# 打印结果
|
||||
if breakpoint_list:
|
||||
print(f"📋 断点列表:")
|
||||
for i, name in enumerate(breakpoint_list, 1):
|
||||
print(f" {i}. {name}")
|
||||
else:
|
||||
print("⚠️ 未获取到任何断点,列表可能为空")
|
||||
|
||||
return breakpoint_list
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 获取断点列表失败: {str(e)}")
|
||||
# 可以在这里打印更多调试信息
|
||||
try:
|
||||
page_source = driver.page_source
|
||||
print("📄 当前页面源码已保存,可用于调试")
|
||||
# 可以将page_source保存到文件,方便分析
|
||||
with open("debug_page_source.xml", "w", encoding="utf-8") as f:
|
||||
f.write(page_source)
|
||||
except:
|
||||
pass
|
||||
return breakpoint_list
|
||||
|
||||
|
||||
def go_upload_config_page(self):
|
||||
"""点击img_2_layout(上传页面按钮)"""
|
||||
@@ -343,8 +407,8 @@ class UploadConfigPage:
|
||||
'com.bjjw.cjgc:id/point_values'
|
||||
)
|
||||
|
||||
self.logger.info(f"找到 {len(point_name_elements)} 个测点")
|
||||
self.logger.info(f"找到 {len(point_value_elements)} 个数据元素")
|
||||
# self.logger.info(f"找到 {len(point_name_elements)} 个测点")
|
||||
# self.logger.info(f"找到 {len(point_value_elements)} 个数据元素")
|
||||
|
||||
# 提取每个测点的数据
|
||||
for i, (name_element, value_element) in enumerate(zip(point_name_elements, point_value_elements)):
|
||||
@@ -383,7 +447,7 @@ class UploadConfigPage:
|
||||
|
||||
point_data.append(point_info)
|
||||
|
||||
self.logger.info(f"测点 {i+1}: {point_name}")
|
||||
# self.logger.info(f"测点 {i+1}: {point_name}")
|
||||
# self.logger.info(f"完整数据: {point_value}")
|
||||
|
||||
except Exception as e:
|
||||
@@ -487,54 +551,54 @@ class UploadConfigPage:
|
||||
self.logger.error(f"检查上传配置页面时发生意外错误: {str(e)}")
|
||||
return False
|
||||
|
||||
def collect_all_point_data(self, results_dir):
|
||||
"""循环滑动收集所有测点数据,直到没有新数据出现"""
|
||||
all_point_data = []
|
||||
seen_point_names = set() # 用于跟踪已经见过的测点名称
|
||||
max_scroll_attempts = 20 # 最大滑动次数,防止无限循环
|
||||
scroll_attempt = 0
|
||||
# def collect_all_point_data(self, results_dir):
|
||||
# """循环滑动收集所有测点数据,直到没有新数据出现"""
|
||||
# all_point_data = []
|
||||
# seen_point_names = set() # 用于跟踪已经见过的测点名称
|
||||
# max_scroll_attempts = 20 # 最大滑动次数,防止无限循环
|
||||
# scroll_attempt = 0
|
||||
|
||||
self.logger.info("开始循环滑动收集所有测点数据...")
|
||||
# self.logger.info("开始循环滑动收集所有测点数据...")
|
||||
|
||||
while scroll_attempt < max_scroll_attempts:
|
||||
scroll_attempt += 1
|
||||
self.logger.info(f"第 {scroll_attempt} 次尝试获取数据...")
|
||||
# while scroll_attempt < max_scroll_attempts:
|
||||
# scroll_attempt += 1
|
||||
# self.logger.info(f"第 {scroll_attempt} 次尝试获取数据...")
|
||||
|
||||
# 获取当前屏幕的测点数据
|
||||
current_point_data = self.get_point_data()
|
||||
# # 获取当前屏幕的测点数据
|
||||
# current_point_data = self.get_point_data()
|
||||
|
||||
if not current_point_data:
|
||||
self.logger.info("当前屏幕没有测点数据,停止滑动")
|
||||
break
|
||||
# if not current_point_data:
|
||||
# self.logger.info("当前屏幕没有测点数据,停止滑动")
|
||||
# break
|
||||
|
||||
# 统计新发现的测点
|
||||
new_points_count = 0
|
||||
for point in current_point_data:
|
||||
point_name = point.get('point_name')
|
||||
if point_name and point_name not in seen_point_names:
|
||||
# 新测点,添加到结果集
|
||||
all_point_data.append(point)
|
||||
seen_point_names.add(point_name)
|
||||
new_points_count += 1
|
||||
# # 统计新发现的测点
|
||||
# new_points_count = 0
|
||||
# for point in current_point_data:
|
||||
# point_name = point.get('point_name')
|
||||
# if point_name and point_name not in seen_point_names:
|
||||
# # 新测点,添加到结果集
|
||||
# all_point_data.append(point)
|
||||
# seen_point_names.add(point_name)
|
||||
# new_points_count += 1
|
||||
|
||||
self.logger.info(f"本次获取到 {len(current_point_data)} 个测点,其中 {new_points_count} 个是新测点")
|
||||
# self.logger.info(f"本次获取到 {len(current_point_data)} 个测点,其中 {new_points_count} 个是新测点")
|
||||
|
||||
# 如果没有新数据,停止滑动
|
||||
if new_points_count == 0:
|
||||
self.logger.info("没有发现新测点,停止滑动")
|
||||
break
|
||||
# # 如果没有新数据,停止滑动
|
||||
# if new_points_count == 0:
|
||||
# self.logger.info("没有发现新测点,停止滑动")
|
||||
# break
|
||||
|
||||
# 滑动到下一页
|
||||
self.logger.info("滑动到下一页...")
|
||||
if not self.swipe_up():
|
||||
self.logger.warning("滑动失败,停止收集")
|
||||
break
|
||||
# # 滑动到下一页
|
||||
# self.logger.info("滑动到下一页...")
|
||||
# if not self.swipe_up():
|
||||
# self.logger.warning("滑动失败,停止收集")
|
||||
# break
|
||||
|
||||
# 等待页面稳定
|
||||
time.sleep(1)
|
||||
# # 等待页面稳定
|
||||
# time.sleep(1)
|
||||
|
||||
self.logger.info(f"数据收集完成,共获取 {len(all_point_data)} 个测点数据")
|
||||
return all_point_data
|
||||
# self.logger.info(f"数据收集完成,共获取 {len(all_point_data)} 个测点数据")
|
||||
# return all_point_data
|
||||
|
||||
def collect_check_all_point_data(self, max_variation):
|
||||
"""循环滑动收集所有测点数据,直到没有新数据出现"""
|
||||
@@ -547,7 +611,7 @@ class UploadConfigPage:
|
||||
|
||||
while scroll_attempt < max_scroll_attempts:
|
||||
scroll_attempt += 1
|
||||
self.logger.info(f"第 {scroll_attempt} 次尝试获取数据...")
|
||||
# self.logger.info(f"第 {scroll_attempt} 次尝试获取数据...")
|
||||
|
||||
# 获取当前屏幕的测点数据
|
||||
current_point_data = self.get_point_data()
|
||||
@@ -951,7 +1015,7 @@ class UploadConfigPage:
|
||||
|
||||
if workinfo_names:
|
||||
workinfo_name = workinfo_names[0] # 主要工况
|
||||
self.logger.info(f"为{work_type_name}({work_type_str})选择主要工况: {workinfo_name}")
|
||||
# self.logger.info(f"为{work_type_name}({work_type_str})选择主要工况: {workinfo_name}")
|
||||
|
||||
try:
|
||||
# 点击工况选择按钮
|
||||
@@ -1445,7 +1509,7 @@ class UploadConfigPage:
|
||||
EC.element_to_be_clickable((AppiumBy.XPATH, option_xpath))
|
||||
)
|
||||
option_element.click()
|
||||
self.logger.info(f"通过文本定位成功选择工况: {condition_name}")
|
||||
# self.logger.info(f"通过文本定位成功选择工况: {condition_name}")
|
||||
return True
|
||||
except TimeoutException:
|
||||
self.logger.debug(f"通过文本'{condition_name}'未找到工况选项")
|
||||
@@ -1512,12 +1576,12 @@ class UploadConfigPage:
|
||||
# return False
|
||||
# 跳转到上传配置页面
|
||||
if not go_main_click_tabber_button(self.driver, self.device_id, "com.bjjw.cjgc:id/img_2_layout"):
|
||||
logging.error(f"设备 {self.device_id} 跳转到上传配置页面失败")
|
||||
logging.error(f"设备 {self.device_id} 跳转到上传配置页面失败(下载操作)")
|
||||
return False
|
||||
|
||||
# 根据断点名称点击上传按钮
|
||||
if not self.click_upload_by_breakpoint_name(breakpoint_name):
|
||||
self.logger.error("点击上传按钮失败")
|
||||
self.logger.error("点击上传按钮失败(下载操作)")
|
||||
return False
|
||||
|
||||
if not self.handle_upload_dialog():
|
||||
@@ -1765,7 +1829,7 @@ class UploadConfigPage:
|
||||
|
||||
# 跳转到上传配置页面
|
||||
if not go_main_click_tabber_button(self.driver, self.device_id, "com.bjjw.cjgc:id/img_2_layout"):
|
||||
logging.error(f"设备 {self.device_id} 跳转到测量页面失败")
|
||||
logging.error(f"设备 {self.device_id} 跳转到上传配置页面失败")
|
||||
return False
|
||||
|
||||
# 根据断点名称点击上传按钮
|
||||
@@ -1846,17 +1910,7 @@ class UploadConfigPage:
|
||||
|
||||
# 获取线路的所有工况信息
|
||||
work_conditions = apis.get_work_conditions_by_linecode(self.line_num)
|
||||
# work_conditions = {'1962527': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 2},
|
||||
# '0299815Z2': {'sjName': '王顺', 'workinfoname': '冬休', 'work_type': 2},
|
||||
# '0299820H1': {'sjName': '王顺', 'workinfoname': '架桥机(运梁车) 首次通过后', 'work_type': 4},
|
||||
# '0431248D1': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 4},
|
||||
# '0431248D2': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 4},
|
||||
# '0299815Z1': {'sjName': '王顺', 'workinfoname': '架桥机(运梁车) 首次通过前', 'work_type': 2},
|
||||
# '0431289D2': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 4},
|
||||
# '0431330D1': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 2},
|
||||
# '0431330D2': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 2},
|
||||
# '0431370D1': {'sjName': '王顺', 'workinfoname': '轨道板(道床)铺设后,第1个月', 'work_type': 2}}
|
||||
self.logger.info(f"获取线路工况信息成功: {work_conditions}")
|
||||
# self.logger.info(f"获取线路工况信息成功: {work_conditions}")
|
||||
if not work_conditions:
|
||||
self.logger.error("获取工况信息失败")
|
||||
return False
|
||||
@@ -1896,9 +1950,9 @@ class UploadConfigPage:
|
||||
self.logger.error("点击保存上传并处理弹窗失败")
|
||||
return False
|
||||
|
||||
# 暂不上传,使用返回按钮替代。
|
||||
self.driver.back()
|
||||
return True
|
||||
# # 暂不上传,使用返回按钮替代。
|
||||
# self.driver.back()
|
||||
# return True
|
||||
|
||||
|
||||
# 等待上传,查看loading弹窗。没有就下一个
|
||||
|
||||
Reference in New Issue
Block a user