Published by breki on 19 Apr 2008 at 06:43 pm
Using White To Test Kosmos GUI
After a few weeks of work on my new framework for multidocument interfaces called BrekiViews (yes, I know I promised to write a little about it, but I just didn’t have enough time and concentration to put the brainstorms in my head into some coherent words) and refactoring Kosmos code to use it, I’m finally able to show some basic stuff in the new Kosmos GUI application. It’s all pretty simple at the moment, I got just one menu item working: File | Open Project. But I wanted to use this opportunity and start using White from ThoughtWorks to write automated GUI tests, since I was looking forward to trying the White out.
Documentation (Or The Lack Of It)
Unfortunately, the first impressions aren’t that good. The worst problem is lack of documentation. There are some pages written on the project’s CodePlex page and I also stumbled on a few posts which have some more examples on how to use it, but in general the API is undocumented. NDoc documentation that comes in the latest release just contains the API reference, without any human-generated documentation. It even states that it’s based on .NET Framework 1.1, which was obviously autogenerated and is probably wrong, since the API includes generics. I haven’t checked the source code directly though, maybe there is something there.
Yes I know, it’s an open source project and I shouldn’t expect too much, but I still think that such a project for which the whole purpose is to be used through an API should contain at least some documentation. Otherwise you spend a lot of time experimenting with the API to achieve the results.
Keyboard Problems
Like most other UI testing frameworks, White too suffers from quirks. I wanted to start the “Open Project” menu action using the keyboard shortcut, so I tried with:
mainWindow.Keyboard.Enter ("o");
Which ended up forcing me to restart the computer, since the OS started acting very funny, as if the Ctrl key was still being pressed. I guess I should have added
to unpress the Ctrl key, but I’m not sure, since I couldn’t find any documentation on using the keyboard in White. Anyway, a helper method that would accept a shortcut as a string (something like KeyboardInput.Press (“Ctrl+O”) would be very helpful).
Clicking The Menus
After abandoning the keyboard approach, I tried to start “Open Project” by clicking on the menu item. I did some experimenting and finally managed to write a basic test, here’s the whole test fixture:
public class BasicTests
{
[Test]
public void OpenProject()
{
Menu fileMenu = mainWindow.MenuBar.MenuItem ("File");
fileMenu.Click();
Menu openProjectMenu = fileMenu.SubMenu ("Open Project…");
openProjectMenu.Click();
}
[SetUp]
public void Setup()
{
application = Application.Launch (@”..\..\..\Kosmos.Gui\bin\Debug\Kosmos.Gui.exe");
mainWindow = application.GetWindow ("Kosmos GUI", InitializeOption.NoCache);
Assert.IsNotNull(mainWindow);
Assert.IsTrue (mainWindow.DisplayState == DisplayState.Restored);
}
[TearDown]
public void Teardown()
{
application.Kill();
}
private Application application;
private Window mainWindow;
}
White Facade
From my experience with other UI testing frameworks, if you intend to do more than a few simple UI tests it is a good idea to create some sort of a facade around the testing API. This way you simplify the interface to common use cases you typically use and eliminate any nasty quirks (like memory or resource leaks). Bil Simser has done something to that affect for White, although I don’t support his views on (not) using Setup and Teardown methods in unit tests.
Even better: why not implement a fluent inteface facade? Something like
or
would be much nicer than the above code, don’t you think? Okey, I’m oversimplifying, I know
, but I will try to do something in the direction of a fluent interface facade, since I don’t intend to abandon the White just yet.


Vivek Singh on 19 Apr 2008 at 21:08 #
I am sorry for your not so good experience. I am making sure the next release, NDoc is much better. As you said, there is lot more documentation in the source which for some reason didnt showup in the NDoc and I didn’t check it. Yes, but the intention is not to leave it undocumented. There is a release coming up next week. I would try to address some of your concerns. Also if you face any issue you can raise it is IssueTracker or Discussion List. I like your idea of Ctrl+O. Regarding providing a wrapper, the release after next should answer something around this. It ready for use but I havent released it because it isnt documented completely yet. Sorry again, but your ideas are welcome.
breki on 19 Apr 2008 at 21:18 #
Vivek,
Thank you for the response. I’ll be sure to check out the documentation in the source code.
Regarding shortcuts, here’s a simple code to parse WinForms-style shortcuts from the string into a System.Windows.Forms.Keys enumeration (although I suppose you would want something more general, not WinForms, for White):
try { KeysConverter converter = new KeysConverter (); Keys shortcutKeys = (Keys)converter.ConvertFromInvariantString (value); } catch (ArgumentException) { throw new ArgumentException(String.Format (System.Globalization.CultureInfo.InvariantCulture, “Illegal hotkey ‘{0}’.”, value)); }
Looking forward to the next release of White. And keep up the good work!
igorbrejc.net » White Facade - Fluent Interface For Writing Tests Using White on 21 Apr 2008 at 19:06 #
[...] few days ago I wrote about my first experiences in using White. I mentioned I wanted to create a facade around the White API in order to avoid constantly retyping [...]
adam on 27 Dec 2009 at 23:02 #
I installed openSUSE on VMWare Player and did a quick test of Kosmos.Gui on it. It actually runs without any additional code changes. It does sometimes break down on the “Open file” dialog however, but this looks like a bug in Mono. Kosmos.Gui runs quite slowly on my VM, especially on zoomed-in maps when it has to draw street names. Anyway, test it if you want on your Linux machines and let me know about your experience.
breki on 28 Dec 2009 at 16:55 #
@adam,
Thanks for the info. I actually did test it a long time ago on an openSUSE virt. image and, as you point out, it runs quite slowly. I suspect the biggest problem is Mono’s implementation of GDI+ drawing engine. The good news is that I’m in the process of rewriting the Kosmos drawing code and it will be much less reliant on GDI+ (there will be an alternative Cairo mode which I hope will run faster on Mono). So I hope Kosmos v3 will be more portable. Also, I’ve become an (almost) regular user of Linux now, so it will be easier for me to support Kosmos on Linux.