views:

496

answers:

2

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!

A: 

Hi. 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.

carstenlenz
A: 

@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.

Jay
To be more precise - there are no easy options. I did not dig into the code but I think you may try to replace Java wrapper of that native dialog and mock implementation. Sure the test would not be complete but testing underlying native GUI is not part of unit testing anyway.
Petr Gladkikh