diff --git a/ImprovementsHistory/20131208.txt b/ImprovementsHistory/test_results/20131208-1.txt similarity index 100% rename from ImprovementsHistory/20131208.txt rename to ImprovementsHistory/test_results/20131208-1.txt diff --git a/ImprovementsHistory/20131208-2.ps1 b/ImprovementsHistory/test_results/20131208-2.ps1 similarity index 100% rename from ImprovementsHistory/20131208-2.ps1 rename to ImprovementsHistory/test_results/20131208-2.ps1 diff --git a/ImprovementsHistory/test_results/20131209-1.txt b/ImprovementsHistory/test_results/20131209-1.txt new file mode 100644 index 000000000..bef4f3d8b --- /dev/null +++ b/ImprovementsHistory/test_results/20131209-1.txt @@ -0,0 +1,13 @@ +GetUiaControlCommandTestFixture: +GetControlByValue_Win32_WildCard_TimeoutDefault + +GetUiaControlRelativesTestFixture: +GetControlAncestors_MoreThanOne + +ParameterlessSearchTestFixture: +GetControl_Win32_X2_SearchInAutomationIdClassName_Timeout2000 +GetControl_Win32_X2_SearchInClassName_Timeout2000 +GetControl_Win32_X2_SearchInNameClassName_Timeout2000 +GetControl_Win32_X2_SearchInValue_Timeout2000 + +UiaRunner? \ No newline at end of file diff --git a/UIA/UIAutomation/Commands/Common/ShowUIADesktopCommand.cs b/UIA/UIAutomation/Commands/Common/ShowUIADesktopCommand.cs index c7bad0df2..b1f69edbe 100644 --- a/UIA/UIAutomation/Commands/Common/ShowUIADesktopCommand.cs +++ b/UIA/UIAutomation/Commands/Common/ShowUIADesktopCommand.cs @@ -25,6 +25,8 @@ protected override void BeginProcessing() try{ // 20131109 //AutomationElement showDesktopButton = + // 20131209 + /* IUiElement showDesktopButton = // 20131109 //AutomationElement.RootElement.FindFirst( @@ -33,6 +35,14 @@ protected override void BeginProcessing() new PropertyCondition( AutomationElement.NameProperty, "Show desktop")); + */ + IUiElement showDesktopButton = + UiElement.RootElement.FindFirst( + TreeScope.Children, + new PropertyCondition( + AutomationElement.ClassNameProperty, + "TrayShowDesktopButtonWClass")); + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // 20131208 // InvokePattern invPtrn = @@ -41,6 +51,9 @@ protected override void BeginProcessing() // showDesktopButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; // invPtrn.Invoke(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + IMySuperInvokePattern invPtrn = + showDesktopButton.GetCurrentPattern(InvokePattern.Pattern); + invPtrn.Invoke(); /* InvokePattern invPtrn = showDesktopButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; diff --git a/UIA/UIAutomation/Commands/Discovery/GetUIACurrentPatternCommand.cs b/UIA/UIAutomation/Commands/Discovery/GetUIACurrentPatternCommand.cs index 3d45aa03a..416a82a30 100644 --- a/UIA/UIAutomation/Commands/Discovery/GetUIACurrentPatternCommand.cs +++ b/UIA/UIAutomation/Commands/Discovery/GetUIACurrentPatternCommand.cs @@ -94,10 +94,12 @@ protected override void ProcessRecord() AutomationPattern pattern = UiaHelper.GetPatternByName(Name); - - result = + // 20131209 + result = UiaHelper.GetCurrentPattern(ref _control, pattern); + // result = + // _control.GetCurrentPattern(pattern); WriteVerbose(this, result); diff --git a/UIA/UIAutomation/Helpers/Inheritance/PatternCmdletBase.cs b/UIA/UIAutomation/Helpers/Inheritance/PatternCmdletBase.cs index a0fa528a4..884df4d76 100644 --- a/UIA/UIAutomation/Helpers/Inheritance/PatternCmdletBase.cs +++ b/UIA/UIAutomation/Helpers/Inheritance/PatternCmdletBase.cs @@ -388,20 +388,15 @@ internal void CallValuePatternForSet(PatternCmdletBase cmdlet, IUiElement contro internal void CallValuePatternForGet(PatternCmdletBase cmdlet, IUiElement control, IUiElement inputObject) { try { -//Console.WriteLine("CallValuePatternForGet 00001"); // IMySuperValuePattern valuePatternGet = control.GetValuePattern(); // IMySuperValuePattern valuePatternGet = control.GetCurrentPattern(); IMySuperValuePattern valuePatternGet = control.GetCurrentPattern(ValuePattern.Pattern); -//Console.WriteLine("CallValuePatternForGet 00002"); object result = null; -//Console.WriteLine("CallValuePatternForGet 00003"); if (valuePatternGet != null) { -//Console.WriteLine("CallValuePatternForGet 00004"); result = valuePatternGet.Current.Value; WriteVerbose(this, "the result is " + result); WriteObject(this, result); } else { -//Console.WriteLine("CallValuePatternForGet 00005"); WriteVerbose(this, "couldn't get ValuePattern"); WriteObject(this, result); } diff --git a/UIA/UIAutomation/Helpers/UnderlyingCode/Adapter/AutomationElementAdapter.cs b/UIA/UIAutomation/Helpers/UnderlyingCode/Adapter/AutomationElementAdapter.cs index 3956b8c00..96e5bda81 100644 --- a/UIA/UIAutomation/Helpers/UnderlyingCode/Adapter/AutomationElementAdapter.cs +++ b/UIA/UIAutomation/Helpers/UnderlyingCode/Adapter/AutomationElementAdapter.cs @@ -127,168 +127,16 @@ public virtual object GetCurrentPropertyValue(AutomationProperty property, bool } } - // public virtual object GetCurrentPattern(AutomationPattern pattern) - // public virtual object GetCurrentPattern(AutomationPattern pattern) - // public virtual object GetCurrentPattern(AutomationPattern pattern) public virtual N GetCurrentPattern(AutomationPattern pattern) - // public virtual object GetCurrentPattern(object pattern) where N : IBasePattern - // where O : AutomationIdentifier { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: if (Preferences.FromCache) { - // 20131208 -// if (pattern.Id == ExpandCollapsePattern.Pattern.Id) { -// IMySuperExpandCollapsePattern expandCollapsePattern = -// AutomationFactory.GetMySuperExpandCollapsePattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as ExpandCollapsePattern); -// return expandCollapsePattern; -// } else if (pattern.Id == InvokePattern.Pattern.Id) { -// IMySuperInvokePattern invokePattern = -// AutomationFactory.GetMySuperInvokePattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as InvokePattern); -// return invokePattern; -// } else if (pattern.Id == ScrollItemPattern.Pattern.Id) { -// IMySuperScrollItemPattern scrollItemPattern = -// AutomationFactory.GetMySuperScrollItemPattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as ScrollItemPattern); -// return scrollItemPattern; -// } else if (pattern.Id == ScrollPattern.Pattern.Id) { -// IMySuperScrollPattern scrollPattern = -// AutomationFactory.GetMySuperScrollPattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as ScrollPattern); -// return scrollPattern; -// } else if (pattern.Id == TogglePattern.Pattern.Id) { -// IMySuperTogglePattern togglePattern = -// AutomationFactory.GetMySuperTogglePattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as TogglePattern); -// return togglePattern; -// } else if (pattern.Id == ValuePattern.Pattern.Id) { -// IMySuperValuePattern valuePattern = -// AutomationFactory.GetMySuperValuePattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as ValuePattern);//, -// return valuePattern; -// } else if (pattern.Id == WindowPattern.Pattern.Id) { -// IMySuperWindowPattern windowPattern = -// AutomationFactory.GetMySuperWindowPattern( -// this, -// _elementHolderNet.GetCachedPattern(pattern) as WindowPattern);//, -// return windowPattern; -// } else { -// return _elementHolderNet.GetCachedPattern(pattern); -// } -//return AutomationFactory.GetMySuperPattern(this, _elementHolderNet.GetCachedPattern(pattern) as AutomationPattern); //(pattern as AutomationPattern))); // as AutomationPattern);// as O); - - // return (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCachedPattern(pattern) as AutomationPattern)); - // return (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCachedPattern(pattern) as AutomationPattern)); return (N)AutomationFactory.GetMySuperPattern(this, _elementHolderNet.GetCachedPattern(pattern)); } else { - // 20131208 -// if (pattern.Id == ExpandCollapsePattern.Pattern.Id) { -// IMySuperExpandCollapsePattern expandCollapsePattern = -// AutomationFactory.GetMySuperExpandCollapsePattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as ExpandCollapsePattern); -// return expandCollapsePattern; -// } else if (pattern.Id == InvokePattern.Pattern.Id) { -// IMySuperInvokePattern invokePattern = -// AutomationFactory.GetMySuperInvokePattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as InvokePattern); -// return invokePattern; -// } else if (pattern.Id == ScrollItemPattern.Pattern.Id) { -// IMySuperScrollItemPattern scrollItemPattern = -// AutomationFactory.GetMySuperScrollItemPattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as ScrollItemPattern); -// return scrollItemPattern; -// } else if (pattern.Id == ScrollPattern.Pattern.Id) { -// IMySuperScrollPattern scrollPattern = -// AutomationFactory.GetMySuperScrollPattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as ScrollPattern); -// return scrollPattern; -// } else if (pattern.Id == SelectionItemPattern.Pattern.Id) { -// IMySuperSelectionItemPattern selectionItemPattern = -// AutomationFactory.GetMySuperSelectionItemPattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as SelectionItemPattern); -// return selectionItemPattern; -// } else if (pattern.Id == SelectionPattern.Pattern.Id) { -// IMySuperSelectionPattern selectionPattern = -// AutomationFactory.GetMySuperSelectionPattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as SelectionPattern); -// return selectionPattern; -// } else if (pattern.Id == TogglePattern.Pattern.Id) { -// IMySuperTogglePattern togglePattern = -// AutomationFactory.GetMySuperTogglePattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as TogglePattern); -// return togglePattern; -// } else if (pattern.Id == ValuePattern.Pattern.Id) { -// IMySuperValuePattern valuePattern = -// AutomationFactory.GetMySuperValuePattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as ValuePattern); -// return valuePattern; -// } else if (pattern.Id == WindowPattern.Pattern.Id) { -// IMySuperWindowPattern windowPattern = -// AutomationFactory.GetMySuperWindowPattern( -// this, -// _elementHolderNet.GetCurrentPattern(pattern) as WindowPattern); -// return windowPattern; -// } else { -// return this._elementHolderNet.GetCurrentPattern(pattern); -// } - - - - //return AutomationFactory.GetMySuperPattern(this, _elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern);// as O); - // var aaaa = AutomationFactory.GetMySuperPattern(this, _elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern); //(pattern as AutomationPattern))); // as AutomationPattern);// as O); - - // this works -// var aaaa = (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern)); //(pattern as AutomationPattern))); // as AutomationPattern);// as O); -//Console.WriteLine("gcp " + aaaa.GetType().Name); -//return aaaa; - // return (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern)); - - -// var a1 = _elementHolderNet.GetCurrentPattern(pattern); -// if (null == a1) { -// Console.WriteLine("null == _elementHolderNet.GetCurrentPattern(pattern)"); -// } else { -// Console.WriteLine(a1.GetType().Name); -// var a2 = a1 as AutomationPattern; -// if (null == a2) { -// Console.WriteLine("null == _elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern"); -// } else { -// Console.WriteLine(a2.GetType().Name); -// var a3 = (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern)); -// if (null == a3) { -// Console.WriteLine("null == (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern))"); -// } -// } -// } - // return (N)AutomationFactory.GetMySuperPattern(this, (_elementHolderNet.GetCurrentPattern(pattern) as AutomationPattern)); return (N)AutomationFactory.GetMySuperPattern(this, _elementHolderNet.GetCurrentPattern(pattern)); - - - - - - - - - } // case InnerElementTypes.AutomationElementCom: // // @@ -298,10 +146,24 @@ public virtual N GetCurrentPattern(AutomationPattern pattern) // default: /// return Preferences.FromCache ? _elementHolderNet.GetCachedPattern(pattern) : _elementHolderNet.GetCurrentPattern(pattern); } - // 20131208 - // return null; + return default(N); } + + // internal virtual object GetCurrentPatternLegacy(AutomationPattern pattern) + public virtual object GetCurrentPattern(AutomationPattern pattern) + { + switch (_innerElementType) { + case InnerElementTypes.AutomationElementNet: + return _elementHolderNet.GetCurrentPattern(pattern); +// case InnerElementTypes.AutomationElementCom: +// // + // case InnerElementTypes.UiElement: + // return _elementHolderAdapter.GetCurrentPattern(pattern); + default: + return _elementHolderNet.GetCurrentPattern(pattern); + } + } public virtual bool TryGetCurrentPattern(AutomationPattern pattern, out object patternObject) { diff --git a/UIA/UIAutomation/Helpers/UnderlyingCode/ExtensionMethods/ExtensionMethodsElement.cs b/UIA/UIAutomation/Helpers/UnderlyingCode/ExtensionMethods/ExtensionMethodsElement.cs index d77058918..147c2dbad 100644 --- a/UIA/UIAutomation/Helpers/UnderlyingCode/ExtensionMethods/ExtensionMethodsElement.cs +++ b/UIA/UIAutomation/Helpers/UnderlyingCode/ExtensionMethods/ExtensionMethodsElement.cs @@ -451,224 +451,6 @@ internal static string GetElementControlTypeString(this IUiElement element) } #region Patterns -// public static N GetCurrentPattern(this IUiElement element) where N : IBasePattern //where O : AutomationPattern -// { -// N resultPattern = AutomationFactory.GetMySuperPattern(element, null); -//Console.WriteLine("extension method 0001"); -//if (null == resultPattern) { -// Console.WriteLine("null == resultPattern"); -//} -// object pattern = null; -// -// if (element.TryGetCurrentPattern((O as AutomationPattern), out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -//Console.WriteLine("extension method 0003"); -// -// return resultPattern; -// } - -// public static IMySuperExpandCollapsePattern GetExpandCollapsePattern(this IUiElement element) -// { -//// IMySuperExpandCollapsePattern resultPattern = AutomationFactory.GetMySuperExpandCollapsePattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperExpandCollapsePattern(element, (pattern as ExpandCollapsePattern)); -//// } -//// -// IMySuperExpandCollapsePattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperInvokePattern GetInvokePattern(this IUiElement element) -// { -//// IMySuperInvokePattern resultPattern = AutomationFactory.GetMySuperInvokePattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperInvokePattern(element, (pattern as InvokePattern)); -//// } -//// -// IMySuperInvokePattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperScrollItemPattern GetScrollItemPattern(this IUiElement element) -// { -//// IMySuperScrollItemPattern resultPattern = -//// AutomationFactory.GetMySuperScrollItemPattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(ScrollItemPattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperScrollItemPattern(element, (pattern as ScrollItemPattern)); -//// } -//// -// IMySuperScrollItemPattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(ScrollItemPattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperScrollPattern GetScrollPattern(this IUiElement element) -// { -//// IMySuperScrollPattern resultPattern = -//// AutomationFactory.GetMySuperScrollPattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(ScrollPattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperScrollPattern(element, (pattern as ScrollPattern)); -//// } -//// -// IMySuperScrollPattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(ScrollPattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperSelectionItemPattern GetSelectionItemPattern(this IUiElement element) -// { -//// IMySuperSelectionItemPattern resultPattern = -//// AutomationFactory.GetMySuperSelectionItemPattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperSelectionItemPattern(element, (pattern as SelectionItemPattern)); -//// } -//// -// IMySuperSelectionItemPattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperSelectionPattern GetSelectionPattern(this IUiElement element) -// { -//// IMySuperSelectionPattern resultPattern = -//// AutomationFactory.GetMySuperSelectionPattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(SelectionPattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperSelectionPattern(element, (pattern as SelectionPattern)); -//// } -//// -// IMySuperSelectionPattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(SelectionPattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperTogglePattern GetTogglePattern(this IUiElement element) -// { -//// IMySuperTogglePattern resultPattern = AutomationFactory.GetMySuperTogglePattern(element, null); -//// object pattern = null; -//// -//// if (element.TryGetCurrentPattern(TogglePattern.Pattern, out pattern)) { -//// resultPattern = -//// AutomationFactory.GetMySuperTogglePattern(element, (pattern as TogglePattern)); -//// } -//// -// IMySuperTogglePattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(TogglePattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -// public static IMySuperValuePattern GetValuePattern(this IUiElement element) -// { -// // 20131208 -// // IMySuperValuePattern resultPattern = AutomationFactory.GetMySuperValuePattern(element, null); -////Console.WriteLine("extension method 00001"); -// IMySuperValuePattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -////Console.WriteLine("extension method 00002"); -// object pattern = null; -////Console.WriteLine("extension method 00003"); -// -// -// if (element.TryGetCurrentPattern(ValuePattern.Pattern, out pattern)) { -////Console.WriteLine("extension method 00004"); -// resultPattern = -// // 20131208 -// // AutomationFactory.GetMySuperValuePattern(element, (pattern as ValuePattern)); -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -////Console.WriteLine("extension method 00005"); -// } -// -////Console.WriteLine("extension method 00006"); -// -// return resultPattern; -// } -// -// public static IMySuperWindowPattern GetWindowPattern(this IUiElement element) -// { -// IMySuperWindowPattern resultPattern = AutomationFactory.GetMySuperPattern(element, null); -// object pattern = null; -// -// if (element.TryGetCurrentPattern(WindowPattern.Pattern, out pattern)) { -// resultPattern = -// AutomationFactory.GetMySuperPattern(element, (pattern as AutomationPattern)); -// } -// -// return resultPattern; -// } -// -//// public T GetValuePattern(this IUiElement element) -//// { -//// T result = null; -//// -//// if (element.TryGetCurrentPattern(ValuePattern.Pattern)) { -//// result = -//// element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; -//// } -//// -//// return result; -//// } #endregion Patterns } } diff --git a/UIA/UIAutomation/Helpers/UnderlyingCode/UIAHelper.cs b/UIA/UIAutomation/Helpers/UnderlyingCode/UIAHelper.cs index 352fc9dd6..62eb95d1d 100644 --- a/UIA/UIAutomation/Helpers/UnderlyingCode/UIAHelper.cs +++ b/UIA/UIAutomation/Helpers/UnderlyingCode/UIAHelper.cs @@ -1856,6 +1856,8 @@ internal static AutomationPattern GetPatternByName(string patternName) // // as System.Windows.Automation.AutomationPattern; // result = resPattern; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + object resPattern = + element.GetCurrentPattern(ptrn); return result; } diff --git a/UIA/UIAutomation/Interface/IAutomationElementAdapter.cs b/UIA/UIAutomation/Interface/IAutomationElementAdapter.cs index dfb714f02..74e1ff0b7 100644 --- a/UIA/UIAutomation/Interface/IAutomationElementAdapter.cs +++ b/UIA/UIAutomation/Interface/IAutomationElementAdapter.cs @@ -28,6 +28,7 @@ public interface IUiElement : IDisposable // object GetCurrentPattern(AutomationPattern pattern) where N : IBasePattern; // IBasePattern GetCurrentPattern(AutomationPattern pattern) where N : IBasePattern; N GetCurrentPattern(AutomationPattern pattern) where N : IBasePattern; + object GetCurrentPattern(AutomationPattern pattern); // object GetCurrentPattern(object pattern) where N : IBasePattern; bool TryGetCurrentPattern(AutomationPattern pattern, out object patternObject); object GetCachedPropertyValue(AutomationProperty property); diff --git a/UIA/UIAutomation/pull requests/UIAutomation.cs b/UIA/UIAutomation/pull requests/UIAutomation.cs index 965e6954a..fd4b9ebfc 100644 --- a/UIA/UIAutomation/pull requests/UIAutomation.cs +++ b/UIA/UIAutomation/pull requests/UIAutomation.cs @@ -1,223 +1,230 @@ -// + //namespace AVG.Automation.Cmdlets -//{ -// extern alias UIANET; -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Text; -// using System.Management.Automation; -// using System.Windows.Automation; -// using System.Text.RegularExpressions; -// using System.Runtime.InteropServices; -// using System.Collections; -// using System.Diagnostics; -// using NativeTypes; -// using UIAutomation; -// -// /// -// /// Invokes selected WindowPattern on AutomationElement -// /// -// [Cmdlet(VerbsLifecycle.Invoke, "UiaWindowPattern")] -// public class InvokeUiaWindowPattern : Cmdlet -// { -// /// -// /// Parent object that is target for pattern -// /// -// [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] -// // 20131109 -// //public AutomationElement InputObject { get; set; } -// public IUiElement InputObject { get; set; } -// -// /// -// /// Pattern name to be invoked -// /// -// [Parameter(Mandatory = true, Position = 2)] -// [ValidateSet("Close", "Maximize", "Minimize", "Restore")] -// public string PatternName { get; set; } -// -// protected override void ProcessRecord() -// { -// base.ProcessRecord(); -// -// if (InputObject.Current.ControlType == ControlType.Window) -// { -// // 20131208 -// // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// // WindowPattern windowPattern = InputObject.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; -// // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// -// try -// { -// switch (PatternName.ToLower()) -// { -// case "close": -// windowPattern.Close(); -// break; -// -// case "maximize": -// windowPattern.SetWindowVisualState(WindowVisualState.Maximized); -// break; -// -// case "minimize": -// windowPattern.SetWindowVisualState(WindowVisualState.Minimized); -// break; -// -// case "restore": -// windowPattern.SetWindowVisualState(WindowVisualState.Normal); -// break; -// } -// } -// catch (InvalidOperationException) -// { -// ArgumentException ex = new ArgumentException("Target window doesn't support '" + PatternName + "' pattern."); -// ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); -// } -// } -// else -// { -// ArgumentException ex = new ArgumentException("Cannot call WindowPattern on object that is not a Window."); -// ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); -// } -// } -// } -// -// /// -// /// Sets control to foreground -// /// -// [Cmdlet(VerbsCommon.Set, "UiaControlForeground")] -// public class SetUiaControlForeground : Cmdlet -// { -// /// -// /// Window to be set to foreground -// /// -// [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] -// // 20131109 -// //public AutomationElement InputObject { get; set; } -// public IUiElement InputObject { get; set; } -// -// protected override void ProcessRecord() -// { -// base.ProcessRecord(); -// -// if (InputObject.Current.NativeWindowHandle != 0) -// { -// NativeMethods.SetForegroundWindow((IntPtr)InputObject.Current.NativeWindowHandle); -// } -// else -// { -// InputObject.SetFocus(); -// } -// -// WriteObject(InputObject); -// } -// } -// -// /// -// /// Puts DateTime into DateTimePicker Win32 object -// /// -// [Cmdlet(VerbsCommon.Set, "UiaDateTimePickerDate")] -// public class SetUiaDateTimePickerDate : Cmdlet -// { -// /// -// /// DateTimePicker input object -// /// -// [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] -// // 20131109 -// //public AutomationElement InputObject { get; set; } -// public IUiElement InputObject { get; set; } -// -// /// -// /// DateTime to bet set -// /// -// [Parameter(Mandatory = true, Position = 2)] -// public DateTime Date { get; set; } -// -// const uint DTM_FIRST = 0x1000; -// const uint DTM_SETSYSTEMTIME = DTM_FIRST + 2; -// const ushort GDT_VALID = 0; -// -// private void injectMemory(int procId, byte[] buffer, out IntPtr hndProc, out IntPtr lpAddress) -// { -// // open process and get handle -// hndProc = NativeMethods.OpenProcess(ProcessAccessFlags.All, true, procId); -// -// if (hndProc == (IntPtr)0) -// { -// AccessViolationException ex = new AccessViolationException("Unable to attach to process with an id " + procId); -// ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); -// } -// -// // allocate memory for object to be injected -// lpAddress = NativeMethods.VirtualAllocEx(hndProc, (IntPtr)null, (uint)buffer.Length, -// AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite); -// -// if (lpAddress == (IntPtr)0) -// { -// AccessViolationException ex = new AccessViolationException("Unable to allocate memory to proces with an id " + procId); -// ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); -// } -// -// // write data to process -// const uint wrotelen = 0; -// // uint wrotelen = 0; -// NativeMethods.WriteProcessMemory(hndProc, lpAddress, buffer, (uint)buffer.Length, (UIntPtr)wrotelen); -// -// if (Marshal.GetLastWin32Error() == 0) return; -// AccessViolationException ex2 = new AccessViolationException("Unable to write memory to process with an id " + procId); -// ThrowTerminatingError(new ErrorRecord(ex2, "AccessDenined", ErrorCategory.SecurityError, null)); -// -// /* -// if (Marshal.GetLastWin32Error() != 0) -// { -// AccessViolationException ex = new AccessViolationException("Unable to write memory to process with an id " + procId); -// ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); -// } -// */ -// } -// -// protected override void ProcessRecord() -// { -// base.ProcessRecord(); -// -// // initialize SYSTEMTIME -// int structMemLen = Marshal.SizeOf(typeof(SYSTEMTIME)); -// byte[] buffer = new byte[structMemLen]; -// SYSTEMTIME sysTime = new SYSTEMTIME(Date); -// -// // get memory size of SYSTEMTIME -// IntPtr dataPtr = Marshal.AllocHGlobal(structMemLen); -// Marshal.StructureToPtr(sysTime, dataPtr, true); -// Marshal.Copy(dataPtr, buffer, 0, structMemLen); -// Marshal.FreeHGlobal(dataPtr); -// -// IntPtr hndProc = IntPtr.Zero; -// IntPtr lpAddress = IntPtr.Zero; -// int procId = InputObject.Current.ProcessId; -// int inputHandle = InputObject.Current.NativeWindowHandle; -// -// try -// { -// // inject new SYSTEMTIME into process memory -// injectMemory(procId, buffer, out hndProc, out lpAddress); -// -// // set DateTime to object via pointer to injected SYSTEMTIME -// NativeMethods.SendMessage((IntPtr)inputHandle, DTM_SETSYSTEMTIME, (IntPtr)GDT_VALID, lpAddress); -// } -// finally -// { -// // release memory and close handle -// if (lpAddress != (IntPtr)0 || lpAddress != IntPtr.Zero) -// { -// // we don't really care about the result because if release fails there is nothing we can do about it -// bool relState = NativeMethods.VirtualFreeEx(hndProc, lpAddress, 0, FreeType.Release); -// } -// -// if (hndProc != (IntPtr)0 || hndProc != IntPtr.Zero) -// { -// NativeMethods.CloseHandle(hndProc); -// } -// } -// } -// } -//} +namespace UIAutomation +{ + extern alias UIANET; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Management.Automation; + using System.Windows.Automation; + using System.Text.RegularExpressions; + using System.Runtime.InteropServices; + using System.Collections; + using System.Diagnostics; + // using NativeTypes; + using UIAutomation; + + /// + /// Invokes selected WindowPattern on AutomationElement + /// + [Cmdlet(VerbsLifecycle.Invoke, "UiaWindowPattern")] + public class InvokeUiaWindowPattern : Cmdlet + { + /// + /// Parent object that is target for pattern + /// + [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] + // 20131109 + //public AutomationElement InputObject { get; set; } + public IUiElement InputObject { get; set; } + + /// + /// Pattern name to be invoked + /// + [Parameter(Mandatory = true, Position = 2)] + [ValidateSet("Close", "Maximize", "Minimize", "Restore")] + public string PatternName { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + if (InputObject.Current.ControlType == ControlType.Window) + { + // 20131208 + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // WindowPattern windowPattern = InputObject.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + IMySuperWindowPattern windowPattern = InputObject.GetCurrentPattern(WindowPattern.Pattern); + + try + { + switch (PatternName.ToLower()) + { + case "close": + windowPattern.Close(); + break; + + case "maximize": + windowPattern.SetWindowVisualState(WindowVisualState.Maximized); + break; + + case "minimize": + windowPattern.SetWindowVisualState(WindowVisualState.Minimized); + break; + + case "restore": + windowPattern.SetWindowVisualState(WindowVisualState.Normal); + break; + } + } + catch (InvalidOperationException) + { + ArgumentException ex = new ArgumentException("Target window doesn't support '" + PatternName + "' pattern."); + ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); + } + } + else + { + ArgumentException ex = new ArgumentException("Cannot call WindowPattern on object that is not a Window."); + ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null)); + } + } + } + + /// + /// Sets control to foreground + /// + [Cmdlet(VerbsCommon.Set, "UiaControlForeground")] + public class SetUiaControlForeground : Cmdlet + { + /// + /// Window to be set to foreground + /// + [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] + // 20131109 + //public AutomationElement InputObject { get; set; } + public IUiElement InputObject { get; set; } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + if (InputObject.Current.NativeWindowHandle != 0) + { + NativeMethods.SetForegroundWindow((IntPtr)InputObject.Current.NativeWindowHandle); + } + else + { + InputObject.SetFocus(); + } + + WriteObject(InputObject); + } + } + + /// + /// Puts DateTime into DateTimePicker Win32 object + /// + [Cmdlet(VerbsCommon.Set, "UiaDateTimePickerDate")] + public class SetUiaDateTimePickerDate : Cmdlet + { + /// + /// DateTimePicker input object + /// + [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] + // 20131109 + //public AutomationElement InputObject { get; set; } + public IUiElement InputObject { get; set; } + + /// + /// DateTime to bet set + /// + [Parameter(Mandatory = true, Position = 2)] + public DateTime Date { get; set; } + + const uint DTM_FIRST = 0x1000; + const uint DTM_SETSYSTEMTIME = DTM_FIRST + 2; + const ushort GDT_VALID = 0; + + private void injectMemory(int procId, byte[] buffer, out IntPtr hndProc, out IntPtr lpAddress) + { + // open process and get handle + // hndProc = NativeMethods.OpenProcess(ProcessAccessFlags.All, true, procId); + hndProc = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, true, procId); + + if (hndProc == (IntPtr)0) + { + AccessViolationException ex = new AccessViolationException("Unable to attach to process with an id " + procId); + ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); + } + + // allocate memory for object to be injected + lpAddress = NativeMethods.VirtualAllocEx(hndProc, (IntPtr)null, (uint)buffer.Length, + // AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite); + NativeMethods.AllocationType.Commit | NativeMethods.AllocationType.Reserve, NativeMethods.MemoryProtection.ExecuteReadWrite); + + if (lpAddress == (IntPtr)0) + { + AccessViolationException ex = new AccessViolationException("Unable to allocate memory to proces with an id " + procId); + ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); + } + + // write data to process + const uint wrotelen = 0; + // uint wrotelen = 0; + NativeMethods.WriteProcessMemory(hndProc, lpAddress, buffer, (uint)buffer.Length, (UIntPtr)wrotelen); + + if (Marshal.GetLastWin32Error() == 0) return; + AccessViolationException ex2 = new AccessViolationException("Unable to write memory to process with an id " + procId); + ThrowTerminatingError(new ErrorRecord(ex2, "AccessDenined", ErrorCategory.SecurityError, null)); + + /* + if (Marshal.GetLastWin32Error() != 0) + { + AccessViolationException ex = new AccessViolationException("Unable to write memory to process with an id " + procId); + ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); + } + */ + } + + protected override void ProcessRecord() + { + base.ProcessRecord(); + + // initialize SYSTEMTIME + // int structMemLen = Marshal.SizeOf(typeof(SYSTEMTIME)); + int structMemLen = Marshal.SizeOf(typeof(NativeMethods.SYSTEMTIME)); + byte[] buffer = new byte[structMemLen]; + // SYSTEMTIME sysTime = new SYSTEMTIME(Date); + NativeMethods.SYSTEMTIME sysTime = new NativeMethods.SYSTEMTIME(Date); + + // get memory size of SYSTEMTIME + IntPtr dataPtr = Marshal.AllocHGlobal(structMemLen); + Marshal.StructureToPtr(sysTime, dataPtr, true); + Marshal.Copy(dataPtr, buffer, 0, structMemLen); + Marshal.FreeHGlobal(dataPtr); + + IntPtr hndProc = IntPtr.Zero; + IntPtr lpAddress = IntPtr.Zero; + int procId = InputObject.Current.ProcessId; + int inputHandle = InputObject.Current.NativeWindowHandle; + + try + { + // inject new SYSTEMTIME into process memory + injectMemory(procId, buffer, out hndProc, out lpAddress); + + // set DateTime to object via pointer to injected SYSTEMTIME + NativeMethods.SendMessage((IntPtr)inputHandle, DTM_SETSYSTEMTIME, (IntPtr)GDT_VALID, lpAddress); + } + finally + { + // release memory and close handle + if (lpAddress != (IntPtr)0 || lpAddress != IntPtr.Zero) + { + // we don't really care about the result because if release fails there is nothing we can do about it + // bool relState = NativeMethods.VirtualFreeEx(hndProc, lpAddress, 0, FreeType.Release); + bool relState = NativeMethods.VirtualFreeEx(hndProc, lpAddress, 0, NativeMethods.FreeType.Release); + } + + if (hndProc != (IntPtr)0 || hndProc != IntPtr.Zero) + { + NativeMethods.CloseHandle(hndProc); + } + } + } + } +} diff --git a/UIA_acceptance_tests.gallio b/UIA_acceptance_tests.gallio new file mode 100644 index 000000000..df8df36ca --- /dev/null +++ b/UIA_acceptance_tests.gallio @@ -0,0 +1,17 @@ + + + + + UIA\UIAutomationTest\bin\Release35\UIAutomationTest.dll + + + + + + + + + + ..\..\..\Users\Alexander\AppData\Roaming\Gallio\Icarus\Reports + test-report-{0}-{1} + \ No newline at end of file