Skip to content

Commit

Permalink
the dynamic object model on elements
Browse files Browse the repository at this point in the history
  • Loading branch information
apetrovskiy committed Dec 23, 2013
1 parent 8972b28 commit 0a3c400
Show file tree
Hide file tree
Showing 34 changed files with 247 additions and 410 deletions.
4 changes: 4 additions & 0 deletions .nbehave/plugin.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<PluginConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CreateHtmlReport>true</CreateHtmlReport>
</PluginConfiguration>
20 changes: 20 additions & 0 deletions ImprovementsHistory/test_results/20131222-1.txt
@@ -0,0 +1,20 @@
ConvertToUiaSearchCriteriaCommandTestFixture:
ConvertToSearchCriteria_ProcessId

GetUiaControlCommandTestFixture:
GetControlByValue_Win32_WildCard_TimeoutDefault

GetUiaControlRelativesTestFixture:
GetControlAncestors_MoreThanOne

GetUiaWindowCommandTestFixture:
GetWindowByName_Win32_Delay2000_NoTaskBar

ParameterlessSearchTestFixture:
GetControl_Win32_X2_SearchInAutomationIdClassName_Timeout2000
GetControl_Win32_X2_SearchInClassName_Timeout2000
GetControl_Win32_X2_SearchInNameClassName_Timeout2000
GetControl_Win32_X2_SearchInValue_Timeout2000

WaitUiaWindowCommandTestFixture:
WaitWindow_ByProcessId_Timeout2000
Expand Up @@ -52,21 +52,21 @@ protected override void BeginProcessing()
if (!NoUI) {
Timeout = 604800000;
// frmRecorder formRecorder =
CurrentData.FormRecorder =
CurrentData.formRecorder =
new RecorderForm(this);
// formRecorder.ShowDialog();
CurrentData.FormRecorder.Show();
CurrentData.FormRecorder.Hide();
CurrentData.formRecorder.Show();
CurrentData.formRecorder.Hide();
try {
Events.SubscribeEvent((object)CurrentData.FormRecorder.btnStop,
Events.SubscribeEvent((object)CurrentData.formRecorder.btnStop,
"BtnStopClick",
"formRecorder",
new PSObject(),
ScriptBlock.Create(""), // CurrentData.formRecorder.BtnStopClick,
true,
false);
} catch { }
CurrentData.FormRecorder.ShowDialog();
CurrentData.formRecorder.ShowDialog();
return;
} else {
UiaHelper.ProcessingTranscript(this);
Expand Down
Expand Up @@ -27,7 +27,9 @@ public GetUiaTreeItemCheckedStateCommand()

#region Parameters
[Parameter(Mandatory = false)]
internal string AutomaitonId { get; set; }
// 20131222
// internal string AutomaitonId { get; set; }
internal string AutomationId { get; set; }
/*
internal new string AutomaitonId { get; set; }
*/
Expand Down
21 changes: 1 addition & 20 deletions UIA/UIAutomation/Helpers/Inheritance/HasTimeoutCmdletBase.cs
Expand Up @@ -171,7 +171,7 @@ protected override void StopProcessing()

foreach (IUiElement window in aeWndCollection) {

cmdlet.WriteVerbose(cmdlet, "Window: name='" + window.Current.Name + "', automaitonId='" + window.Current.AutomationId + "'");
cmdlet.WriteVerbose(cmdlet, "Window: name='" + window.Current.Name + "', automationId='" + window.Current.AutomationId + "'");

// if (exitInnerCycle) {
// //break;
Expand Down Expand Up @@ -741,29 +741,10 @@ private List<IUiElement> GetWindowCollectionByName(string[] windowNames, string
WriteVerbose(this, "trying to get window: by title = " +
windowTitle);

Console.WriteLine("odd 001");
if (null == OddRootElement) {
Console.WriteLine("null == odd");
} else {
Console.WriteLine("null != OddRootElement");
if (null == OddRootElement.Current) {
Console.WriteLine("null == OddRootElement.Current");
} else {
Console.WriteLine(OddRootElement.Current.Name);
Console.WriteLine(OddRootElement.Current.AutomationId);
Console.WriteLine(OddRootElement.Current.ClassName);
Console.WriteLine(OddRootElement.Current.ControlType.ProgrammaticName);
}
}
IUiEltCollection windowCollection =
OddRootElement.FindAll(recurse ? TreeScope.Descendants : TreeScope.Children, conditionsSet);

if (null == windowCollection) {
Console.WriteLine("null = wnd coll");
}

WriteVerbose(this, "trying to run the returnOnlyRightElements method");
// WriteVerbose(this, "collected " + windowCollection.Count.ToString() + " elements for further selection");

windowCollectionByProperties =
ReturnOnlyRightElements(
Expand Down
Expand Up @@ -25,7 +25,7 @@ namespace UIAutomation
// public class UiElement <N, O> : IUiElement //, IInitializable
// where N : IBasePattern
// where O : AutomationPattern
public class UiElement : IUiElement //, IMySuperDockPattern //, IInitializable
public class UiElement : IUiElement
{
private AutomationElement _elementHolderNet;
// //private AutomationElement _elementHolderCom;
Expand Down Expand Up @@ -60,7 +60,6 @@ public UiElement(IUiElement element)
}

[Inject]
// public UiElement(bool fake)
public UiElement()
{
// temporary
Expand Down Expand Up @@ -167,10 +166,9 @@ public virtual N GetCurrentPattern<N>(AutomationPattern pattern)
}
}

return default(N);
// return default(N);
}

// internal virtual object GetCurrentPatternLegacy(AutomationPattern pattern)
public virtual object GetCurrentPattern(AutomationPattern pattern)
{
switch (_innerElementType) {
Expand Down Expand Up @@ -269,11 +267,7 @@ public virtual AutomationElement GetUpdatedCache(CacheRequest request)
}
}

// 20131205
// UIANET
// public IUiElement FindFirst(TreeScope scope, Condition condition)
public virtual IUiElement FindFirst(TreeScope scope, UIANET::System.Windows.Automation.Condition condition)
// public IUiElement FindFirst(TreeScope scope, UIANET::Condition condition)
{
switch (_innerElementType) {
case InnerElementTypes.AutomationElementNet:
Expand All @@ -287,9 +281,6 @@ public virtual IUiElement FindFirst(TreeScope scope, UIANET::System.Windows.Auto
}
}

// 20131205
// UIANET
// public IUiEltCollection FindAll(TreeScope scope, Condition condition)
public virtual IUiEltCollection FindAll(TreeScope scope, UIANET::System.Windows.Automation.Condition condition)
{
switch (_innerElementType) {
Expand All @@ -299,6 +290,8 @@ public virtual IUiEltCollection FindAll(TreeScope scope, UIANET::System.Windows.
// //
case InnerElementTypes.UiElement:
return _elementHolderAdapter.FindAll(scope, condition);
// case InnerElementTypes.Empty:
// return AutomationFactory.GetUiEltCollection(_elementHolderNet.FindAll(scope, condition));
default:
return AutomationFactory.GetUiEltCollection(_elementHolderNet.FindAll(scope, condition));
}
Expand All @@ -318,8 +311,6 @@ public virtual AutomationProperty[] GetSupportedProperties()
}
}

// 20131209
// public virtual AutomationPattern[] GetSupportedPatterns()
public virtual IBasePattern[] GetSupportedPatterns()
{
switch (_innerElementType) {
Expand Down Expand Up @@ -399,7 +390,7 @@ public virtual Point GetClickablePoint()
switch (_innerElementType) {
case InnerElementTypes.AutomationElementNet:
return AutomationFactory.GetUiElementInformation(Preferences.FromCache ? _elementHolderNet.Cached : _elementHolderNet.Current);
// case InnerElementTypes.AutomationElementCom:
// case InnerElementTypes.AutomationElementCom:
// //
case InnerElementTypes.UiElement:
return Preferences.FromCache ? _elementHolderAdapter.Cached : _elementHolderAdapter.Current;
Expand Down Expand Up @@ -554,13 +545,11 @@ public static IUiElement FromHandle(IntPtr controlHandle)
}
}

// public virtual AutomationElement GetSourceElement()
public AutomationElement GetSourceElement()
{
return _elementHolderNet;
}
// public virtual void SetSourceElement(AutomationElement element)
// public virtual void SetSourceElement<T>(T element)

public void SetSourceElement<T>(T element)
{
if (element is AutomationElement) {
Expand Down Expand Up @@ -692,139 +681,6 @@ public virtual IUiElement NavigateToPreviousSibling()
}
#endregion NavigateTo

#region Patterns
#region InvokePattern
internal IUiElement Click()
{
// return this.PerformClick();
this.GetCurrentPattern<IMySuperInvokePattern>(InvokePattern.Pattern).Invoke();
return this;
}

internal IUiElement DoubleClick()
{
// HasControlInputCmdletBase cmdlet =
// new HasControlInputCmdletBase();
// cmdlet.ClickControl(
// cmdlet,
// this,
// false,
// false,
// false,
// false,
// false,
// false,
// true,
// 50,
// Preferences.ClickOnControlByCoordX,
// Preferences.ClickOnControlByCoordY);
//
// return this;
return this.PerformDoubleClick();
}
#endregion InvokePattern
#region SelectionItemPattern
internal IUiElement Select()
{
return this.PerformSelect();
}

internal IUiElement AddToSelection()
{
return this.PerformAddToSelection();
}

internal IUiElement RemoveFromSelection()
{
return this.PerformRemoveFromSelection();
}

internal bool IsSelected
{
// get { return this.GetSelectionItemPattern().Current.IsSelected; }
get { return this.GetIsSelected(); }
}

internal IUiElement SelectionContainer
{
// get { return this.GetSelectionItemPattern().Current.SelectionContainer; }
get { return this.GetSelectionContainer(); }
}
#endregion SelectionItemPattern
#region SelectionPattern
internal IUiElement[] GetSelection()
{
// return this.GetSelectionPattern().Current.GetSelection();
return this.PerformGetSelection();
}

internal bool CanSelectMultiple
{
// get { return this.GetSelectionPattern().Current.CanSelectMultiple; }
get { return this.GetCanSelectMultiple(); }
}

internal bool IsSelectionRequired
{
// get { return this.GetSelectionPattern().Current.IsSelectionRequired; }
get { return this.GetIsSelectionRequired(); }
}
#endregion SelectionPattern
#region TogglePattern
internal IUiElement Toggle()
{
return this.Toggle();
}
//
//// public bool? ToggleState
//// {
//// get {
//// using (ToggleState t = ToggleState) {
////
//// }
//// switch (this.GetTogglePattern().Current.ToggleState) {
//// case ToggleState.Off:
//// return false;
//// case ToggleState.On:
//// return true;
//// case ToggleState.Indeterminate:
//// return null;
////// default:
////// throw new Exception("Invalid value for ToggleState");
//// }
//// }
//// set {
//// switch (value) {
//// case true:
//// this.GetTogglePattern().Current.ToggleState = ToggleState.On;
//// break;
//// case false:
//// this.GetTogglePattern().Current.ToggleState = ToggleState.Off;
//// case null:
//// this.GetTogglePattern().Current.ToggleState = ToggleState.Indeterminate;
////// default:
//////
////// break;
//// }
//// }
//// }
#endregion TogglePattern
#region ValuePattern
internal bool IsReadOnly
{
get { return this.GetCurrentPattern<IMySuperValuePattern>(ValuePattern.Pattern).Current.IsReadOnly; }
}

internal string Value
{
// get { return this.GetValuePattern().Current.Value; }
// set { this.GetValuePattern().SetValue(value); }
get { return this.GetCurrentPattern<IMySuperValuePattern>(ValuePattern.Pattern).Current.Value; }
set { this.GetCurrentPattern<IMySuperValuePattern>(ValuePattern.Pattern).SetValue(value); }
}
#endregion ValuePattern
#endregion Patterns

#region Highlighter
public virtual IUiElement Highlight()
{
Expand Down
Expand Up @@ -16,7 +16,6 @@ namespace UIAutomation
using Ninject;

public struct UiElementInformation : IUiElementInformation
//public class UiElementInformation : IUiElementInformation
{
//private AutomationElement _el;
//private bool _useCache;
Expand Down
Expand Up @@ -19,14 +19,14 @@ public class ErrorHandlingAspect : AbstractInterceptor
{
public override void Intercept(IInvocation invocation)
{
invocation.Proceed();
// try {
// invocation.Proceed();
// } catch (Exception eOnInvocation) {
// Exception eNewException =
// new Exception(eOnInvocation.Message);
// throw eNewException;
// }
// invocation.Proceed();
try {
invocation.Proceed();
} catch (Exception eOnInvocation) {
Exception eNewException =
new Exception("Method " + invocation.Method.Name + ": " + eOnInvocation.Message);
throw eNewException;
}

}
}
Expand Down
Expand Up @@ -20,7 +20,8 @@ public class InputValidationAspect : AbstractInterceptor
{
public override void Intercept(IInvocation invocation)
{
foreach (var argument in invocation.GenericArguments) {
// foreach (var argument in invocation.GenericArguments) {
foreach (var argument in invocation.Arguments) {
// if (null == argument) {
// if (argument is AutomationElement) {
// // throw
Expand Down
Expand Up @@ -23,8 +23,6 @@ public class MethodSelectorAspect : AbstractInterceptor

public override void Intercept(IInvocation invocation)
{
// bool returnItself = true;

try {
if (!AlreadySelected) {
AlreadySelected = true;
Expand Down

0 comments on commit 0a3c400

Please sign in to comment.