Thursday, 20 March 2014

Writing Better Coded UI Test?

Yesterday I asked from my colleagues how to optimize a Coded UI test that I have written to run an InstallSheild wizard. No one replied to me, so I decided to investigate on my own.

OK here is the code I have in my Coded UI test which runs for 25 seconds (Installsheild wizard only consumes bout 6-7 seconds).


   Keyboard.SendKeys(@"C:\Deploy\Install\DiskImages\DISK1\setup.exe");

        Keyboard.SendKeys("{ENTER}");

        WinWindow wizard = new WinWindow();
        wizard.SearchProperties.Add(WinWindow.PropertyNames.Name, "My App - InstallSheild Wizard");


        WinButton next = new WinButton(wizard);
        next.SearchProperties.Add(WinButton.PropertyNames.ControlType, "Button", WinButton.PropertyNames.Name, "Next >");

        Mouse.Click(next) 

Here is the test execution time and the detail log


It takes lot of time to detect the "Next"  button (21 Seconds).


With some trial and error below code did the best

     Keyboard.SendKeys(@"C:\Deploy\Install\DiskImages\DISK1\setup.exe");

        Keyboard.SendKeys("{ENTER}");

        WinWindow wizard = new WinWindow();
        wizard.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "MsiDialogCloseClass");


        WinButton next = new WinButton(wizard);
        next.SearchProperties.Add(WinButton.PropertyNames.ControlType, "Button", WinButton.PropertyNames.Name, "Next >");

        Mouse.Click(next) 
The change to ClassName did the trick.

wizard.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "MsiDialogCloseClass");



Now finding "Next"  button with 6 seconds (Installer initial running time)


With much better code using a great extension class for Coded UI by Kris Lankford


 // Launch the InstallShield wizard
            var setup = ApplicationUnderTest.Launch(@"C:\Deploy\Install\DiskImages\DISK1\setup.exe");

            // Find the wizard
            WinWindow wizard = setup.Container.SearchFor(new { ClassName = "MsiDialogCloseClass" });

            // Click on Next button in first step
            Mouse.Click(wizard.SearchFor(new { Name = "Next >" }));
managed to hit 8 seconds. Wow! 3 times faster than original ... way to go!


1 comment:

Anonymous said...

I'm building "hand-coded" CUITs, which I write about on my blog.

Some posts:

-- Clean and DRY Verifiers
-- Keep Your Page Objects DRY
-- Object Not Found? Log the Context!
-- Encapsulate the GUI Tool?
-- Getters and Setters

Popular Posts