Tools: add referecne to UIAutmationClient and UIAutomationTypes. Inspect.exe under local Windows SDK directory, used for find AutomationId, name of logical tree, similar to Scoop. Process p = Process.Start(@"..\..\..\TryoutUITesting\bin\Debug\TryoutUITesting.exe"); AutomationElement desktop = AutomationElement.RootElement; AutomationElement mainWin =null; while( (mainWin= desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow")))==null) {} AutomationElement button= mainWin.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "btn")); InvokePattern buttonClick = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; buttonClick.Invoke(); AutomationElement textbox = mainWin.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "tbx")); TextPattern textboxText= textbox.GetCurrentPattern(TextPattern.Pattern) as TextPattern; string result = textboxText.DocumentRange.GetText(-1); Debug.Assert(result == "Foo");
from System.Diagnostics import Process from System.Diagnostics import Debug import clr clr.AddReference("UIAutomationClient") clr.AddReference("UIAutomationTypes") from System.Windows.Automation import * from System.Windows.Automation import PropertyCondition def main(): p=Process.Start("C:\\working\\TryoutWPFTesting\\TryoutWPFTesting\\bin\\Debug\\TryoutWPFTesting.exe") desktop=AutomationElement.RootElement mainWin =None while (mainWin==None): mainWin= desktop.FindFirst(TreeScope.Children, PropertyCondition(AutomationElement.NameProperty, "MainWindow")) button= mainWin.FindFirst(TreeScope.Children, PropertyCondition(AutomationElement.AutomationIdProperty, "btn")) buttonClick = button.GetCurrentPattern(InvokePattern.Pattern) buttonClick.Invoke() textbox = mainWin.FindFirst(TreeScope.Children, PropertyCondition(AutomationElement.AutomationIdProperty, "tbx")) textboxText= textbox.GetCurrentPattern(TextPattern.Pattern) result = textboxText.DocumentRange.GetText(-1); Debug.Assert(result == "Foo"); p.WaitForExit() if __name__=="__main__": main()
No comments:
Post a Comment