locked
Using UI Automation to close window in unit test RRS feed

  • Question

  • I'm using UI Automation to run a unit test that tests whether a window closes:

    bool hasClosed = false;
    CustomWindow.Closed += new EventHandler((sender, e) => hasClosed = true);
    
    CustomWindow.Show();
    var customWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "CustomWindow"));
    (customWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern).Close();
    
    Assert.IsTrue(hasClosed);

    however, this test fails.  I know I could call CustomWindow.Close(), and the test does then pass, but unfortunatly, this is a simplified example in which calling close directly on CustomWindow is not an option.

    Thursday, January 3, 2013 10:40 PM

Answers

All replies