Monday, November 5, 2007

Windows desktop GUI testing and file dialogs

In most cases development of desktop GUI applications are much more pleasant than web-development (yes, today with JS libraries, it can be disputted, but I win in that contest ;)) . But... one case of development - functional testing - was never been easier in desktop development than in web development.

Just because of application nature. When you have markuped interface - you can easy write code to check whether you web page has needed tag (control) or not and other operations. Tools like Selenium, Watir or something else can provide you good framework to do such thing in transparent way. It much more difficult in your OS - you need to find your form by name, find needed control - often by-hand. Yes, for a long time big companies sold automated GUI-test tools (like IBM Rational or Mercury). But your know, i don't like tools like this - it's operations often non-transparent, non-reliable, non-customizable, complicated to add in build process n etc.

So, until recently, I often prefer not to test GUI-code. And know i do it with NUnitForms. Because it's awesome - just think - it can test Windows native modal dialogs like MessageBox or FileDialog!

You can read about it here or here.

One note that I can add to this is explanation of strange behaviour of windows file dialogs. Unlike MessageBox file dialogs in windows initially have "Open" title - not your own. So for that case NUnitForms has special ExpectFileDialog method, which do nothing more than set modal dialog name to Open.

So your code look like this:


1 ExpectFileDialog("CancelSaveDialog");

 

1 public void CancelSaveDialog() 2 { 3 HandleSaveFileDialog(delegate(SaveFileDialogTester tester) 4 { 5 tester.ClickCancel(); 6 }); 7 } 8 9 public void HandleSaveFileDialog(Action<SaveFileDialogTester> action) 10 { 11 SaveFileDialogTester fileDialogTester = new SaveFileDialogTester("Select backup file"); 12 action.Invoke(fileDialogTester); 13 }

This code works fine on my notebook, but failed on some other computers. The cause is system locale. On my notebook i have english locale, and other computers has Russian locale - and File Dialog opens with not "Open" title but with "Открыть" (open in russian) title.


So, I decline ExpectFileDialog in favor with ExpectModal with my selection of needed title:


1 CultureInfo culture = CultureInfo.CurrentUICulture; 2 3 string saveFileDialogWindowsCaption = culture.TwoLetterISOLanguageName=="ru"?"Открыть":"Open"; 4 5 ExpectModal(saveFileDialogWindowsCaption, "OkSaveDialog");

But maybe any we can directly get dialog name in windows?