Rasmus Møller Selsmark

On software test and test automation

Pattern for closing ApplicationUnderTest instance in CodedUI tests

clock April 21, 2012 21:30 by author rasmus

In his talk Building Robust, Maintainable Coded UI Tests with Visual Studio 2010 at Belgium TechDays 2011, Brian Keller shows the concept of “using using" (slide 11 in his slide deck) in order to dispose application under test after test has finished.

Of course it’s useful to clean up after your tests, but as I learned the hard way this week (although I‘m certainly not the first one to blog about it…), remember to end your UI based tests, with verifying that your application actually can close without crashing. In our case, a javascript window was blocking execution, which my automated test simply ignored and passed…

My pattern for solving this, is the following code, that besides using an ApplicationUnderTest as suggested by Brian Keller, also tries to close the window (a browser instance in this case) before ending the test case.

/// <summary>
/// Creates and updates a case in Captia UI
/// </summary>
public void TC17015_CreatingAndEditingACase()
    // Step: Log on to Captia and click the button “Create case”.
    ApplicationUnderTest browserWindow = CaptiaMainUIActions.OpenCaptia(TestConfig.Instance.CaptiaBaseUrl);

        // Execute test steps/actions...


private static void CloseCaptiaAndVerify(ApplicationUnderTest browserWindow)
    bool captiaClosed = WaitForm.Wait(
        () => ((browserWindow.Process == null) || (browserWindow.Process.HasExited)),
        TimeSpan.FromSeconds(10), "Waiting for Captia window to close.", 2);

    Assert.IsTrue(captiaClosed, "Expected Captia window to be closed.");

private static void DisposeBrowserWindowIfNotClosed(ApplicationUnderTest browserWindow)
    if ((browserWindow != null) && (browserWindow.Process != null) && (!browserWindow.Process.HasExited))

The method CloseCaptiaAndVerify() uses my CodedUI UIMap to click the upper-right cross to close the window, and a custom-made WaitForm to wait up to ten seconds (polling every 2 seconds) to verify that window was actually closed. Otherwise test fails.

The killer string :)

clock April 9, 2012 09:22 by author rasmus

I use this string from time to time when testing applications. It verifies/tests the following areas:

  • Unicode (the "лежт" part)
  • SQL injection (the single and double-quotes)
  • HTML formatting (the "<" sign etc)

The string is: <a '% &x " лежт F8E5>

Embarrassingly this was the result after testing it on one of my personal websites :)