Handling SWT Dialog boxes while running tests in headless mode using SWTBOT
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!
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.
@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.
精彩评论