wpfui-automationmicrosoft-ui-automationflaui

UIAutomation FlaUI - Detect opening windows on application level


I am using FlaUI for test automation and it works fine so far. Now I am trying to detect opening windows and while plain UIAutomation offers to register an eventhandler for "AutomationElement.RootElement" I cannot find a way to translate this to FlaUI as it always expects an AutomationElement. I can only think of the MainWindow, but this changes with Splash, Login, Enviroment-Selections, etc.

This is what I have now, but it does not fire when I open a window:

Window win = app.GetMainWindow(automation, TimeSpan.FromSeconds(5));
                UIA3AutomationEventHandler automationEventHandler = new UIA3AutomationEventHandler(win.FrameworkAutomationElement, automation.EventLibrary.Window.WindowOpenedEvent, TestAction);
                automation.NativeAutomation.AddAutomationEventHandler(automation.EventLibrary.Window.WindowOpenedEvent.Id,automation.NativeAutomation.GetRootElement(), (Interop.UIAutomationClient.TreeScope)TreeScope.Descendants, null, automationEventHandler);

Following the working plain UIAutomation code:

Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
                AutomationElement.RootElement,
                TreeScope.Descendants,
                someDelegate);

Any help would be highly appreciated! Thanks everybody!


Solution

  • FlaUI has a GetDesktop method on the automation object which is the RootElement. You should be able to register an event there.