动机

通常,在回放记录的GUI测试时,鼠标的确切位置无关紧要。相反,我们更关心鼠标是否在所需的UI项内单击。但是,实际上确实需要鼠标坐标。 (考虑一下文本编辑器的测试,您需要将光标放置在精确的字符上。)对于大多数类型, 压扁 默认情况下,将记录具有(x,y)坐标的鼠标点击并将其写入脚本。在这里,我们向您展示如何将Squish配置为在没有坐标的情况下记录特定QML类型。从脚本中删除坐标信息将简化测试脚本,提高测试脚本的可读性并简化测试脚本的维护。

Qt QML示例

让’我们来看一个示例脚本’ve interacted with a custom (not derived from BasicButton) 按钮QML类型。默认情况下,我们的鼠标点击记录为(x,y)坐标:

mouseClick(waitForObject(names.o9_Button), 4, 34, Qt.LeftButton) mouseClick(waitForObject(names.o8_Button), 27, 31, Qt.LeftButton) mouseClick(waitForObject(names.o_Button_2), 13, 37, Qt.LeftButton) mouseClick(waitForObject(names.c_Button), 13, 28, Qt.LeftButton)
Code language: CSS (css)

这些坐标相对于项目的左上角。让’现在看在没有他们的情况下如何录制。

自定义没有坐标的记录Qt测试

Many settings for customizing the way Qt application tests are recorded in 压扁 are located in the qtwrapper.ini file, located in SQUISHDIR/etc/.

RecordWithoutCoordinates is one option in qtwrapper.ini, and it is a list of types. These types can be C++ or QML types. BasicButtonQQuickText are both already there, but not our user-defined Button from the example script above. We can simply add it to the list, and our changes will affect all future recordings:

RecordWithoutCoordinates = "BasicButton", "QQuickText"<strong>, "Button"</strong>
Code language: JavaScript (javascript)

回到前面的示例,通过为Button类型添加自定义,脚本现在如下所示:

mouseClick(waitForObject(names.o9_Button)) mouseClick(waitForObject(names.o8_Button)) mouseClick(waitForObject(names.o_Button_2)) mouseClick(waitForObject(names.c_Button))
Code language: CSS (css)

包起来

For Button-like types where you always want to click in the middle of the item, adding those types to the RecordWithoutCoordinates list simplifies your recorded test scripts, while making them more robust, easier to follow and (potentially) debug. 

发表评论

您的电子邮件地址不会被公开。 必需的地方已做标记 *

复制链接