使用 SWTBOT 在无头模式下运行测试时处理 SWT 对话框

发布于 2024-08-15 02:45:07 字数 356 浏览 6 评论 0原文

我正在使用 SWT 构建的 eclipse 应用程序上运行 Junit 测试用例。我正在使用 SWTBot 进行 GUI 测试。所以,这是我的问题:

editor.bot().button("Make Excel Template").click();

此代码帮助我在应用程序中生成模板。完成后,它会弹出一个模态对话框,其中包含“确定”消息。但是,我无法让 SWTBot 找到此按钮/小部件/对话框。我不断收到“WidgetNotFoundException”。

有人遇到过这个吗? SWTBot 网站上的官方内容表示,对话框应该在单独的非 UI 线程中运行。然而,提供的示例信息并不丰富。

感谢您的帮助!

I am running a Junit test case on my eclipse application that was built using SWT. I am doing GUI testing using SWTBot. So, here is my problem:

editor.bot().button("Make Excel Template").click();

This code helps me generate a template in my application. Once done, it throws up a Modal Dialog with "OK" as a message. However, I can't get SWTBot to find this button/widget/dialog box. I keep getting a 'WidgetNotFoundException'.

Has someone come across this? official content on the SWTBot website says that dialog boxes should be run in seperate non-UI threads. The examples provided however, aren't very informative.

Appreciate your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑,眼淚并存 2024-08-22 02:45:07

首先,您应该在非 UI 线程中运行测试(如果尚未这样做)。
其次,您可以在执行将弹出对话框的操作后使用条件等待模式对话框出现:

bot.waitUntil(Conditions.shellIsActive("This is the title of the modal dialog "));
bot.button("OK").click();

这解决了我们的计时问题。

First you should run your tests in a non-UI-Thread (if not already doing so).
Second you can use a condition to wait for your modal dialog to appear after executing the action that will bring the dialog up:

bot.waitUntil(Conditions.shellIsActive("This is the title of the modal dialog "));
bot.button("OK").click();

This solved our timing issues.

深海夜未眠 2024-08-22 02:45:07

@carstenlez - 您的解决方案适用于 JFace 对话框。然而,我的应用程序正在使用 MessageBox - 这是一个本机对话框。 SWTBot 不支持本机对话框,所以我几乎没有选择。

@carstenlez - your solution works well for JFace Dialog boxes. My app, however, is making use of a MessageBox - which is a native dialog. SWTBot doesn't support native dialogs, so I am pretty much out of options.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文