qt - Qt的QTest不会通过单击选择下拉列表中的项目
问题描述
有两个下拉菜单。我正在尝试单击 QComboBox 下拉列表中的项目。
为此,我创建了一个为两个下拉菜单启动的函数,以下是摘录:
constexpr int DELAY{ 1000 };
void clickDropDown(int row, QComboBox *comboBox)
{
QListView *dropDownList = comboBox->findChild<QListView *>();
QModelIndex foundIndex{ dropDownList->model()->index(row, 0) };
QRect foundDropDownItem = dropDownList->visualRect(foundIndex);
QPoint foundDropDownItemPosition = foundDropDownItem.center();
QWidget *activeWidget = dropDownList->viewport();
QTest::mouseClick(activeWidget, Qt::LeftButton, Qt::NoModifier, foundDropDownItemPosition);
QTest::qWait(DELAY); // waits 1 second
}
现在流程看起来像这样:
- 显示第一个下拉列表,
- 该项目突出显示 (mouseClick) 作为选择,但不是真正选择,未选择
- UI 测试转到第二列,第一列显示列表中的第一个元素(即最上面的元素),尽管突出显示了什么;
- 第二个下拉列表中的一个项目被选中/选择
所以,第二个列表似乎可以使用这个函数,第一个没有。我需要选择这些项目,而不仅仅是突出显示。
我在Ubuntu 21.04上运行。似乎在Windows 10上运行良好。在 Mac 上似乎失败了。任何建议如何使它工作?
什么有效:
two clicks
+ Enter
,但这会在 MacOs 上崩溃。所以这不是一个真正的解决方案。此外,它会破坏dropDownList
对象,如果 make 有间隔,将导致崩溃。
还有什么不起作用: key down
N次。
有什么建议么?
解决方案
我自己找到了答案。
这是 Qt 的错误(截至 2021 年秋季),如下所述: https ://bugreports.qt.io/browse/QTBUG-77772 。鼠标点击的不是按钮,而是附近的某个点。为什么选择它以及为什么它没有做出其他反应仍然是一个谜。
决定:我让这个测试只在 Windows 和 Linux 上运行,为 Mac 关闭它。
推荐阅读
- javascript - 当前一个输入元素达到特定大小时,如何将焦点移动到另一个输入元素?
- acumatica - 如何自定义发布现金交易批量发布屏幕
- reactjs - 如何根据我的道具的布尔值停止执行我的承诺?
- ios - 使用自定义标志构建 Carthage 依赖项
- javascript - React-native:当输入有空文本时,计算返回 NaN
- javascript - 如何为 js 库中触发的事件传递抑制警告?
- css - CSS 改变每个光标
- video - 如何连接具有不同属性的ffmpeg中的视频?
- selenium - “ChromeHeadless 在 60000 毫秒内没有捕获,正在杀戮。” 仅发生在 Gitlab 托管的 CI/CD 管道中
- tweepy - Tweepy 的特定超时错误解决方法