Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[swtbot-dev] Workaround for Native Dialogs

Hi there,

like probably a couple other testers before me, I got stuck when I
tried to test native dialogs (file selection dialog...).

Until Eclipse makes those dialogs accessible (obviously the best
solution), we can do with a work-around. I tried replacing the native
dialogs with (testable) SWT-Pendants during the test cycle. I've
already done this for a file dialog and for a simple Message box.

Replacing the MessageBox is pretty much straightforward, I simply
replace it with a MessageDialog.

The file selection dialog is more complex. I simply replaced it with
an Input-Dialog, where SWTBot can enter the path to the file.

Reason for this simplicity.

The code, that displays the file selection dialog is only interested
in two cases:
- Dialog returns some String ->  Now, I check, if it represents a
usable file (exists, is readable, writeable ...)
- null or and empty String is returned ->  the user canceled the operation

When I'm testing, I don't want to click through my folder structure, I
just want to enter some fixed path (as this is known in the test).

To switch between production mode with native dialogs and test mode
with those fake dialogs, I use a static factory that handles those
dialogs. At the beginning of the test cycle, the factory is set to
test-mode.

If you are interested in this approach, I will happily contribute this
workaround.

All in all, this solution is far from perfect, but it helps me to test
my user interface. As my application is file-centric, it boils down to
this workaround or no meaningful GUI-testing.

Greetings,

Jan Petranek


Back to the top