提交 292512bb authored 作者: 陈泽健's avatar 陈泽健

封装三个移动端的函数,分别用于设备控制时的异常重试机制以及设备截屏操作,增加相应的异常处理。

上级 498c8ae1
...@@ -414,8 +414,7 @@ def curtain_control(app_drive,wd): ...@@ -414,8 +414,7 @@ def curtain_control(app_drive,wd):
INFO("请检查窗帘上升状态是否正常") INFO("请检查窗帘上升状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_up") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_up")
# 截图获取当前中控屏软件窗帘上升的界面 # 截图获取当前中控屏软件窗帘上升的界面
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "curtain_up")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\curtain_up.png")
sleep(30) sleep(30)
# # 测试报告中补充窗帘上升的截图 # # 测试报告中补充窗帘上升的截图
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_rtsp_up") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_rtsp_up")
...@@ -440,8 +439,7 @@ def curtain_control(app_drive,wd): ...@@ -440,8 +439,7 @@ def curtain_control(app_drive,wd):
INFO("请检查窗帘下降状态是否正常") INFO("请检查窗帘下降状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_down") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_down")
# 截图获取当前中控屏软件窗帘上升的界面 # 截图获取当前中控屏软件窗帘上升的界面
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "curtain_down")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\curtain_down.png")
# 测试报告中补充窗帘下降的截图 # 测试报告中补充窗帘下降的截图
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_rtsp_down") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "curtain_rtsp_down")
logging.info("开始捕获RTSP流中的帧") logging.info("开始捕获RTSP流中的帧")
...@@ -462,8 +460,7 @@ def air_condition_control(app_drive,wd): ...@@ -462,8 +460,7 @@ def air_condition_control(app_drive,wd):
INFO("请检查空调开启的状态是否正常") INFO("请检查空调开启的状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_on") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_on")
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "air_condition_on")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_on.png")
sleep(2) sleep(2)
# 点击【关闭空调】按钮 # 点击【关闭空调】按钮
...@@ -475,8 +472,7 @@ def air_condition_control(app_drive,wd): ...@@ -475,8 +472,7 @@ def air_condition_control(app_drive,wd):
# 这是空调关闭的状态显示 # 这是空调关闭的状态显示
INFO("请检查空调关闭的状态是否正常") INFO("请检查空调关闭的状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_off") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_off")
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "air_condition_off")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_off.png")
sleep(2) sleep(2)
def information_control(app_drive,wd): def information_control(app_drive,wd):
...@@ -557,8 +553,7 @@ def music_control(app_drive,wd): ...@@ -557,8 +553,7 @@ def music_control(app_drive,wd):
# 这是音乐开启播放后的界面显示 # 这是音乐开启播放后的界面显示
INFO("请检查中控屏软件打开音乐播放后的界面状态显示") INFO("请检查中控屏软件打开音乐播放后的界面状态显示")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_on") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_on")
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "music_on")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_on.png")
# 点击【关闭播放音乐】 # 点击【关闭播放音乐】
logging.info("尝试定位【关闭播放音乐】按钮元素,并点击按钮") logging.info("尝试定位【关闭播放音乐】按钮元素,并点击按钮")
...@@ -569,9 +564,7 @@ def music_control(app_drive,wd): ...@@ -569,9 +564,7 @@ def music_control(app_drive,wd):
# 这是音乐关闭播放后的界面显示 # 这是音乐关闭播放后的界面显示
INFO("请检查中控屏软件关闭音乐播放后的界面状态显示") INFO("请检查中控屏软件关闭音乐播放后的界面状态显示")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_off") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_off")
app_drive.get_screenshot_as_file( get_screenshot_with_retry(app_drive, "Control_Manage", "music_off")
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_off.png")
def command_centre_control(rtsp_url,app_drive,wd): def command_centre_control(rtsp_url,app_drive,wd):
open_center_button = app_drive.find_element(AppiumBy.XPATH, open_center_button = app_drive.find_element(AppiumBy.XPATH,
...@@ -715,4 +708,105 @@ def app_quit(device_ip,port=5555): ...@@ -715,4 +708,105 @@ def app_quit(device_ip,port=5555):
# 断开特定 IP 和端口的 ADB 连接 # 断开特定 IP 和端口的 ADB 连接
device_address = f"{device_ip}:{port}" device_address = f"{device_ip}:{port}"
subprocess.run(['adb', 'disconnect', device_address]) subprocess.run(['adb', 'disconnect', device_address])
INFO(f"ADB 连接已断开: {device_address}") INFO(f"ADB 连接已断开: {device_address}")
\ No newline at end of file
def get_screenshot_with_retry(app_drive, module_name, function_name, max_retries=3, retry_delay=5):
"""
使用重试机制获取并保存截图。
参数:
app_drive: 实现了get_screenshot_as_file方法的对象,用于获取截图。
module_name: 用于构造保存截图的目录名称。
function_name: 用于构造截图文件的名称。
max_retries: 最大重试次数,默认为3次。
retry_delay: 重试间隔时间,默认为5秒。
返回值:
无。如果多次尝试截图失败,则抛出异常。
"""
# 获取当前文件的绝对路径
current_file_path = os.path.abspath(__file__)
# 获取当前文件的父级目录
parent_dir = os.path.dirname(current_file_path)
# 构造目标目录路径
target_dir = os.path.join(parent_dir, '..', 'reports', 'imgs', 'Exhibit_Inspect', module_name)
# 确保目标目录存在,如果不存在则创建
os.makedirs(target_dir, exist_ok=True)
# 构造文件路径
file_path = os.path.join(target_dir, f"{function_name}.png")
# 使用循环实现重试机制
for _ in range(max_retries):
try:
# 尝试保存截图
app_drive.get_screenshot_as_file(file_path)
# 如果成功,记录日志并退出函数
logging.info(f"截图保存成功: {file_path}")
return
except Exception as e:
# 如果失败,记录日志并等待重试
logging.warning(f"截图失败,重试中... ({e})")
sleep(retry_delay)
# 如果多次尝试均失败,则抛出异常
raise Exception(f"多次尝试截图失败: {file_path}")
def find_element_with_retry(driver, by, value, max_retries=3, retry_delay=5):
"""
使用重试机制查找元素。
在WebDriver(driver)中通过给定的查找方式(by)和值(value)来查找页面元素。
如果在指定的最大重试次数(max_retries)内仍然找不到元素,则抛出异常。
每次重试之间会有指定的延迟时间(retry_delay)。
参数:
- driver: WebDriver实例,用于执行查找操作。
- by: 查找元素的方式,如XPath、ID等。
- value: 元素的值,根据'by'参数指定的查找方式对应的具体值。
- max_retries: 最大重试次数,默认为3次。
- retry_delay: 每次重试之间的延迟时间,默认为5秒。
返回:
- 返回找到的元素。
异常:
- 如果超过最大重试次数仍未找到元素,则抛出异常。
"""
for _ in range(max_retries):
try:
# 尝试查找元素,如果成功则立即返回元素
return driver.find_element(by, value)
except Exception as e:
# 如果查找元素失败,记录日志并等待一段时间后重试
logging.warning(f"查找元素失败,重试中... ({e})")
sleep(retry_delay)
# 如果达到最大重试次数仍未找到元素,则抛出异常
raise Exception(f"多次尝试查找元素失败: {by}={value}")
def click_with_retry(element, max_retries=3, retry_delay=5):
"""
点击元素的函数,带有重试机制。
参数:
element (obj): 要点击的元素对象。
max_retries (int): 最大重试次数,默认为3次。
retry_delay (int): 每次重试之间的延迟时间,默认为5秒。
异常:
如果超过最大重试次数仍未成功点击元素,则抛出异常。
"""
# 尝试点击元素,直到达到最大重试次数
for _ in range(max_retries):
try:
# 尝试点击元素
element.click()
# 如果点击成功,记录日志并退出函数
logging.info(f"点击元素成功: {element}")
return
except Exception as e:
# 如果点击失败,记录日志并等待下一次重试
logging.warning(f"点击元素失败,重试中... ({e})")
sleep(retry_delay)
# 如果所有重试都失败,抛出异常
raise Exception(f"多次尝试点击元素失败: {element}")
...@@ -224,4 +224,5 @@ ...@@ -224,4 +224,5 @@
- 讯飞系统的定位元素改为CSS,因国际化导致原先的XPATH可能会由变化。 - 讯飞系统的定位元素改为CSS,因国际化导致原先的XPATH可能会由变化。
58. 2025-02-22 58. 2025-02-22
- 排查展厅巡检报告中无纸化会议操作的截图显示错误问题,补充上一无纸化同屏流程的结束同屏操作步骤。在初始化函数补充adb连接是否可用的判断,如连接失败,则不进行后续操作。 - 排查展厅巡检报告中无纸化会议操作的截图显示错误问题,补充上一无纸化同屏流程的结束同屏操作步骤。在初始化函数补充adb连接是否可用的判断,如连接失败,则不进行后续操作。
- 处理展厅巡检中控屏的信息发布屏流程步骤缺失问题,增加异常重试机制。 - 处理展厅巡检中控屏的信息发布屏流程步骤缺失问题,增加异常重试机制。
\ No newline at end of file - 封装三个移动端的函数,分别用于设备控制时的异常重试机制以及设备截屏操作,增加相应的异常处理。
\ No newline at end of file
...@@ -31,10 +31,10 @@ class Exhibition_hall_Control_000x: ...@@ -31,10 +31,10 @@ class Exhibition_hall_Control_000x:
logging.info("等待首页加载...") logging.info("等待首页加载...")
# 先切换界面,再切回灯光控制 # 先切换界面,再切回灯光控制
air_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, air_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[6]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[6]")
logging.info("尝试定位【空气净化】按钮元素,并点击按钮") logging.info("尝试定位【空气净化】按钮元素,并点击按钮")
self.click_with_retry(air_button) click_with_retry(air_button)
sleep(10) sleep(10)
STEP(2, "检查灯光控制功能") STEP(2, "检查灯光控制功能")
...@@ -52,11 +52,11 @@ class Exhibition_hall_Control_000x: ...@@ -52,11 +52,11 @@ class Exhibition_hall_Control_000x:
# 定位灯光控制按钮元素,并点击按钮 # 定位灯光控制按钮元素,并点击按钮
logging.info("尝试定位【灯光控制】按钮元素,并点击按钮") logging.info("尝试定位【灯光控制】按钮元素,并点击按钮")
light_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, light_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button[3]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button[3]")
logging.info("定位成功") logging.info("定位成功")
# 点击【灯光控制】按钮 # 点击【灯光控制】按钮
self.click_with_retry(light_button) click_with_retry(light_button)
sleep(10) sleep(10)
# 这是全部灯光关闭后在软件界面上的状态显示 # 这是全部灯光关闭后在软件界面上的状态显示
...@@ -64,8 +64,8 @@ class Exhibition_hall_Control_000x: ...@@ -64,8 +64,8 @@ class Exhibition_hall_Control_000x:
SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_off") SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_off")
# 截图获取当前软件的灯光控制界面 # 截图获取当前软件的灯光控制界面
self.get_screenshot_with_retry(app_drive, get_screenshot_with_retry(app_drive,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_off.png") "Control_Manage", "light_all_off")
# 调用灯光控制函数 # 调用灯光控制函数
light_control(app_drive) light_control(app_drive)
...@@ -74,8 +74,8 @@ class Exhibition_hall_Control_000x: ...@@ -74,8 +74,8 @@ class Exhibition_hall_Control_000x:
SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_on") SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_on")
# 截图获取当前软件的灯光控制界面 # 截图获取当前软件的灯光控制界面
self.get_screenshot_with_retry(app_drive, get_screenshot_with_retry(app_drive,
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_on.png") "Control_Manage", "light_all_on")
# 这是灯光开启后的截图 # 这是灯光开启后的截图
INFO("请检查灯光开启后的监控视频状态是否正常") INFO("请检查灯光开启后的监控视频状态是否正常")
...@@ -92,20 +92,20 @@ class Exhibition_hall_Control_000x: ...@@ -92,20 +92,20 @@ class Exhibition_hall_Control_000x:
# 切换灯光控制界面 # 切换灯光控制界面
# 灯光测试结束后关闭灯光 # 灯光测试结束后关闭灯光
logging.info("尝试定位【灯光控制】按钮元素,并点击按钮") logging.info("尝试定位【灯光控制】按钮元素,并点击按钮")
light_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, light_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button[3]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.Button[3]")
logging.info("定位成功") logging.info("定位成功")
# 点击【灯光控制】按钮 # 点击【灯光控制】按钮
self.click_with_retry(light_button) click_with_retry(light_button)
sleep(10) sleep(10)
light_control(app_drive) light_control(app_drive)
STEP(3, "检查窗帘的升降功能") STEP(3, "检查窗帘的升降功能")
# 切换至窗帘控制界面 # 切换至窗帘控制界面
logging.info("尝试定位【窗帘控制】按钮元素,并点击按钮") logging.info("尝试定位【窗帘控制】按钮元素,并点击按钮")
curtain_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, curtain_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[4]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[4]")
self.click_with_retry(curtain_button) click_with_retry(curtain_button)
sleep(10) sleep(10)
# 调用窗口上升下降的函数 # 调用窗口上升下降的函数
curtain_control(app_drive, wd) curtain_control(app_drive, wd)
...@@ -113,9 +113,9 @@ class Exhibition_hall_Control_000x: ...@@ -113,9 +113,9 @@ class Exhibition_hall_Control_000x:
STEP(3, "检查空调控制是否正常") STEP(3, "检查空调控制是否正常")
# 切换至空调控制界面 # 切换至空调控制界面
logging.info("尝试定位【空调控制】按钮元素,并点击按钮") logging.info("尝试定位【空调控制】按钮元素,并点击按钮")
air_conditioner_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, air_conditioner_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[5]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[5]")
self.click_with_retry(air_conditioner_button) click_with_retry(air_conditioner_button)
sleep(10) sleep(10)
# 调用空调控制的函数 # 调用空调控制的函数
air_condition_control(app_drive, wd) air_condition_control(app_drive, wd)
...@@ -124,9 +124,9 @@ class Exhibition_hall_Control_000x: ...@@ -124,9 +124,9 @@ class Exhibition_hall_Control_000x:
# 切换至指挥中心控制界面 # 切换至指挥中心控制界面
# 打开指挥中心大屏幕 # 打开指挥中心大屏幕
logging.info("尝试定位【开启指挥中心控制】按钮元素,并点击按钮") logging.info("尝试定位【开启指挥中心控制】按钮元素,并点击按钮")
center_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, center_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[8]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[8]")
self.click_with_retry(center_button) click_with_retry(center_button)
sleep(10) sleep(10)
# 调用指挥中心控制函数 # 调用指挥中心控制函数
command_centre_control(light_rtsp_url, app_drive, wd) command_centre_control(light_rtsp_url, app_drive, wd)
...@@ -134,9 +134,9 @@ class Exhibition_hall_Control_000x: ...@@ -134,9 +134,9 @@ class Exhibition_hall_Control_000x:
STEP(5, "检查音乐控制功能是否正常") STEP(5, "检查音乐控制功能是否正常")
# 切换至音乐区域 # 切换至音乐区域
logging.info("尝试定位【音乐】按钮元素,并点击按钮") logging.info("尝试定位【音乐】按钮元素,并点击按钮")
music_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, music_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[9]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[9]")
self.click_with_retry(music_button) click_with_retry(music_button)
sleep(2) sleep(2)
# 调用音乐控制函数 # 调用音乐控制函数
music_control(app_drive, wd) music_control(app_drive, wd)
...@@ -144,17 +144,17 @@ class Exhibition_hall_Control_000x: ...@@ -144,17 +144,17 @@ class Exhibition_hall_Control_000x:
STEP(6, "检查信息发布界面发布内容功能是否正常") STEP(6, "检查信息发布界面发布内容功能是否正常")
logging.info("尝试定位【发布屏】按钮元素,并点击按钮") logging.info("尝试定位【发布屏】按钮元素,并点击按钮")
information_delivery = self.find_element_with_retry(app_drive, AppiumBy.XPATH, information_delivery = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[7]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[1]/android.widget.Button[7]")
logging.info("定位成功") logging.info("定位成功")
self.click_with_retry(information_delivery) click_with_retry(information_delivery)
sleep(5) sleep(5)
# 打开信息发布播放 # 打开信息发布播放
information_on_button = self.find_element_with_retry(app_drive, AppiumBy.XPATH, information_on_button = find_element_with_retry(app_drive, AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[2]/android.widget.Button[6]") "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[2]/android.widget.Button[6]")
logging.info("定位“发布屏”开启按钮") logging.info("定位“发布屏”开启按钮")
self.click_with_retry(information_on_button) click_with_retry(information_on_button)
sleep(5) sleep(5)
logging.info("信息发布播放开启成功") logging.info("信息发布播放开启成功")
# 调用信息发布控制函数 # 调用信息发布控制函数
...@@ -162,35 +162,4 @@ class Exhibition_hall_Control_000x: ...@@ -162,35 +162,4 @@ class Exhibition_hall_Control_000x:
except Exception as e: except Exception as e:
# 捕获并记录任何发生的错误 # 捕获并记录任何发生的错误
logging.error(f"发生错误: {e}", exc_info=True) logging.error(f"发生错误: {e}", exc_info=True)
\ No newline at end of file
def find_element_with_retry(self, driver, by, value, max_retries=3, retry_delay=5):
for _ in range(max_retries):
try:
return driver.find_element(by, value)
except Exception as e:
logging.warning(f"查找元素失败,重试中... ({e})")
sleep(retry_delay)
raise Exception(f"多次尝试查找元素失败: {by}={value}")
def get_screenshot_with_retry(self, driver, file_path, max_retries=3, retry_delay=5):
for _ in range(max_retries):
try:
driver.get_screenshot_as_file(file_path)
logging.info(f"截图保存成功: {file_path}")
return
except Exception as e:
logging.warning(f"截图失败,重试中... ({e})")
sleep(retry_delay)
raise Exception(f"多次尝试截图失败: {file_path}")
def click_with_retry(self, element, max_retries=3, retry_delay=5):
for _ in range(max_retries):
try:
element.click()
logging.info(f"点击元素成功: {element}")
return
except Exception as e:
logging.warning(f"点击元素失败,重试中... ({e})")
sleep(retry_delay)
raise Exception(f"多次尝试点击元素失败: {element}")
...@@ -3,5 +3,5 @@ trust_host_root_certs: false ...@@ -3,5 +3,5 @@ trust_host_root_certs: false
tunnels: tunnels:
nat1: nat1:
proto: proto:
tcp: 192.168.2.192:80 tcp: 192.168.1.203:80
remote_port: 31133 remote_port: 31133
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论