none
AutomationPeers and IWindowProvider RRS feed

  • Question

  • I am testing several WPF controls and I'm running into some issues when Invoking a button.  Once said button is invoked the program hits the next line of code before the thread actually finishes executing so when I'm doing an assert the execution of the button has yet to happen and gets called later down the line.  I know IWindowProvider supports WaitForInputIdle (since this invoke is launched as Dispatcher.Input) but I'm not sure how to implement it as there are no derived types that support IWindowProvider.  Any suggestions or ideas how I can wait for this thread to complete?  I am putting this controls on a window that is created and grabbing the AutomationPeers that I want to test through a recursive function.

                Control control = contentProvider.GetContentControl(refreshFieldsActionDef);

                Window window = new Window() {Content = control};
                window.Show();

                AutomationPeer rootPeer = UIElementAutomationPeer.CreatePeerForElement(control);

    Thursday, September 23, 2010 4:34 PM

Answers

  • I forgot to reply to this back a while ago.  I just ended up writing a method that will actually yield all threads until the selected dispatcher is finished doing its work.  So if I have buttonAutomationPeer I can just call something like WaitForInputIdle(buttonAutomationPeer.Dispatcher) and it works well.
    • Marked as answer by Chris Judah Tuesday, December 28, 2010 2:04 PM
    Tuesday, December 28, 2010 2:04 PM

All replies

  • Hi Chris Judah,

    WPF application has a Dispatcher in global. So we could use it with the specific DispatcherPriority

          System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new Action(() => { ... }),
            System.Windows.Threading.DispatcherPriority.ContextIdle); //Or other Dispatcher Priorityies

    By the way, if it relates with the UI Automation Testing, there is a fit to it: Visual Studio UI Automation Testing (includes CodedUI)

    Sincerely,
    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download all in one code framework !
    Monday, September 27, 2010 11:48 AM
    Moderator
  • I forgot to reply to this back a while ago.  I just ended up writing a method that will actually yield all threads until the selected dispatcher is finished doing its work.  So if I have buttonAutomationPeer I can just call something like WaitForInputIdle(buttonAutomationPeer.Dispatcher) and it works well.
    • Marked as answer by Chris Judah Tuesday, December 28, 2010 2:04 PM
    Tuesday, December 28, 2010 2:04 PM