Squish moveMouse returns Error: Failed to move the mouse
Squish moveMouse returns Error: Failed to move the mouse
我正在使用 Squish 6.3.0 Beta 版来测试用 Qt 编写的应用程序(我知道有更新的版本,但目前无法升级)。我正在尝试移动鼠标以获取工具提示,但 mouseMove 命令 returns 出现 RuntimeError:无法移动鼠标。包装函数是写在 python:
中的代码
def mouse_move(self, object_name, x, y, timeout=None):
try:
my_obj = waitForObject(object_name, timeout)
logging.debug("Found object: {0}".format(my_obj.objectName))
mouseMove(my_obj, x, y)
logging.debug("Mouse moved to: {object_name}".format(object_name=my_obj.objectName))
except Exception, e:
logging.error("Error: {0}".format(e))
ex_type, ex_value, ex_traceback = sys.exc_info()
trace_back = traceback.extract_tb(ex_traceback)
stack_trace = list()
for trace in trace_back:
stack_trace.append(
"File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3]))
logging.error("Exception type: {0}".format(ex_type.__name__))
logging.error("Exception message: {0}".format(ex_value))
logging.error("Stack trace: {0}".format(stack_trace))
我得到的输出:
16:19:11 DEBUG: Found object: name_of_the_object
16:19:11 ERROR: Error: Failed to move the mouse
16:19:11 ERROR: Exception type: RuntimeError
16:19:11 ERROR: Exception message: Failed to move the mouse
16:19:11 ERROR: Stack trace: path/my_squish_wrapper.py , Line : 170, Func.Name : mouse_move, Message : mouseMove(my_obj, x, y)']
有没有人知道为什么鼠标不能移动?或者我应该检查什么以获得更多信息。
如果只想测试工具提示文本,可以检查 Qt 对象的 "tooltip" 属性。
https://kb.froglogic.com/display/KB/Example+-+Getting+A+Tooltip+%28Qt%29
但是,如果您的用例要求您将鼠标移动到小部件并查看工具提示,您可以尝试更改代码中的 x,y 坐标,或者您也可以选择使用 QCursor.setPos() 如下文所述 - https://kb.froglogic.com/display/KB/Article+-+Moving+the+mouse+cursor+yourself
我已经找到解决这个 mouseMove 问题的方法,如果有人需要的话:
rect = object.globalBounds(my_obj)
x = rect.center().x
y = rect.center().y
QCursor.setPos(x, y)
确保在构建 Squish 时正确配置了 Xtst 包。
我的不是。配置警告我:
Checking whether XTest extension library is available
tmp.cpp:1:34: error: X11/extensions/XTest.h: No such file or directory
tmp.cpp:3: error: ?XTestQueryExtension? was not declared in this scope
安装正确的包后,Squish mouseMove(和 dragAndDrop 操作)又可以工作了。
我正在使用 Squish 6.3.0 Beta 版来测试用 Qt 编写的应用程序(我知道有更新的版本,但目前无法升级)。我正在尝试移动鼠标以获取工具提示,但 mouseMove 命令 returns 出现 RuntimeError:无法移动鼠标。包装函数是写在 python:
中的代码def mouse_move(self, object_name, x, y, timeout=None):
try:
my_obj = waitForObject(object_name, timeout)
logging.debug("Found object: {0}".format(my_obj.objectName))
mouseMove(my_obj, x, y)
logging.debug("Mouse moved to: {object_name}".format(object_name=my_obj.objectName))
except Exception, e:
logging.error("Error: {0}".format(e))
ex_type, ex_value, ex_traceback = sys.exc_info()
trace_back = traceback.extract_tb(ex_traceback)
stack_trace = list()
for trace in trace_back:
stack_trace.append(
"File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3]))
logging.error("Exception type: {0}".format(ex_type.__name__))
logging.error("Exception message: {0}".format(ex_value))
logging.error("Stack trace: {0}".format(stack_trace))
我得到的输出:
16:19:11 DEBUG: Found object: name_of_the_object
16:19:11 ERROR: Error: Failed to move the mouse
16:19:11 ERROR: Exception type: RuntimeError
16:19:11 ERROR: Exception message: Failed to move the mouse
16:19:11 ERROR: Stack trace: path/my_squish_wrapper.py , Line : 170, Func.Name : mouse_move, Message : mouseMove(my_obj, x, y)']
有没有人知道为什么鼠标不能移动?或者我应该检查什么以获得更多信息。
如果只想测试工具提示文本,可以检查 Qt 对象的 "tooltip" 属性。 https://kb.froglogic.com/display/KB/Example+-+Getting+A+Tooltip+%28Qt%29
但是,如果您的用例要求您将鼠标移动到小部件并查看工具提示,您可以尝试更改代码中的 x,y 坐标,或者您也可以选择使用 QCursor.setPos() 如下文所述 - https://kb.froglogic.com/display/KB/Article+-+Moving+the+mouse+cursor+yourself
我已经找到解决这个 mouseMove 问题的方法,如果有人需要的话:
rect = object.globalBounds(my_obj)
x = rect.center().x
y = rect.center().y
QCursor.setPos(x, y)
确保在构建 Squish 时正确配置了 Xtst 包。 我的不是。配置警告我:
Checking whether XTest extension library is available
tmp.cpp:1:34: error: X11/extensions/XTest.h: No such file or directory
tmp.cpp:3: error: ?XTestQueryExtension? was not declared in this scope
安装正确的包后,Squish mouseMove(和 dragAndDrop 操作)又可以工作了。