挤压移动鼠标返回错误:无法移动鼠标



我正在使用Squish版本6.3.0 Beta来测试用Qt编写的应用程序(我知道有更新的版本,但目前无法进行升级(。我正在尝试移动鼠标以获取工具提示,但 mouseMove 命令返回运行时错误:无法移动鼠标。包装器函数是 python 中的 wrienter 代码:

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)']

有谁知道为什么鼠标不能移动?或者我应该检查什么以获取更多信息。

如果有人需要,我找到了此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

安装正确的软件包后,挤压鼠标移动(和拖放操作(再次工作。

如果只想测试工具提示文本,可以检查 Qt 对象的"工具提示"属性。 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

最新更新