提交 3c440f1a authored 作者: 陈泽健's avatar 陈泽健

feat(Base): 添加调整屏幕分辨率功能并优化展厅中控屏测试用例

- 在 base.py 中添加 change_resolution 函数,用于调整屏幕分辨率
- 更新展厅中控屏测试用例中的 XPath 表达式
上级 107af0b5
......@@ -10,6 +10,9 @@ import base64
import psutil
import time
import subprocess
import win32api
import win32con
import win32gui
import logging
from hytest import *
from selenium import webdriver
......@@ -105,6 +108,67 @@ def browser_init(login_type):
# 捕获并记录初始化过程中的任何异常
logging.error(f"浏览器初始化失败:{e}")
# 定义调整屏幕分辨率,仅虚拟机电脑环境跑定时任务需要使用。
def change_resolution(width, height):
"""
调整屏幕分辨率
Args:
width (int): 目标分辨率宽度
height (int): 目标分辨率高度
Returns:
bool: 分辨率是否成功调整
"""
try:
# 获取当前显示设备信息
device = win32api.EnumDisplayDevices(None, 0)
current_device = device.DeviceName
logging.info(f"当前显示设备: {current_device}")
dm = win32api.EnumDisplaySettings(current_device, win32con.ENUM_CURRENT_SETTINGS)
current_res = f"{dm.PelsWidth}x{dm.PelsHeight}"
target_res = f"{width}x{height}"
logging.info(f"当前分辨率: {current_res}, 目标分辨率: {target_res}")
if dm.PelsWidth == width and dm.PelsHeight == height:
logging.warning("目标分辨率与当前分辨率相同,无需调整")
return True
# 设置新分辨率
dm.PelsWidth = width
dm.PelsHeight = height
logging.info(f"尝试设置分辨率为: {target_res}")
# 测试模式验证
test_result = win32api.ChangeDisplaySettings(dm, win32con.CDS_TEST)
if test_result != win32con.DISP_CHANGE_SUCCESSFUL:
error_msg = {
win32con.DISP_CHANGE_BADDUALVIEW: "不支持的双视图模式",
win32con.DISP_CHANGE_BADFLAGS: "无效的标志",
win32con.DISP_CHANGE_BADMODE: "不支持的图形模式",
win32con.DISP_CHANGE_BADPARAM: "无效的参数",
win32con.DISP_CHANGE_FAILED: "显示驱动失败",
}.get(test_result, f"未知错误代码: {test_result}")
logging.error(f"分辨率测试失败: {error_msg}")
return False
# 实际应用更改
apply_result = win32api.ChangeDisplaySettings(dm, 0)
if apply_result != win32con.DISP_CHANGE_SUCCESSFUL:
logging.error("分辨率应用失败")
return False
logging.info("分辨率修改成功")
return True
except Exception as e:
logging.exception(f"分辨率调整过程中发生异常: {str(e)}")
return False
# 从配置项config中获取登录URL
def get_login_url_from_config(login_type):
"""
......
......@@ -32,7 +32,7 @@ class ExhibitionhallControl:
# 先切换界面,再切回灯光控制
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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.Button[6]")
logging.info("尝试定位【空气净化】按钮元素,并点击按钮")
click_with_retry(air_button)
sleep(10)
......@@ -53,7 +53,7 @@ class ExhibitionhallControl:
# 定位灯光控制按钮元素,并点击按钮
logging.info("尝试定位【灯光控制】按钮元素,并点击按钮")
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.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.Button[3]")
logging.info("定位成功")
# 点击【灯光控制】按钮
click_with_retry(light_button)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论