Skip to content

Commit

Permalink
Trying to track down this null reference exeception
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Ginnivan committed Jul 31, 2013
1 parent 83e9eec commit ea018b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ namespace TestStack.White.AutomationElementSearch
{
public class AutomationSearchCondition
{
private readonly List<Condition> conditions = new List<Condition>();
private static readonly Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>> valueMatchers =
static readonly Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>> ValueMatchers =
new Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>>();
readonly List<Condition> conditions = new List<Condition>();

static AutomationSearchCondition()
{
valueMatchers[AutomationElement.NameProperty.ProgrammaticName] = (information, value) => information.Name.Equals(value);
valueMatchers[AutomationElement.AutomationIdProperty.ProgrammaticName] = (information, value) => information.AutomationId.Equals(value);
valueMatchers[AutomationElement.ClassNameProperty.ProgrammaticName] = (information, value) => information.ClassName.Equals(value);
valueMatchers[AutomationElement.ProcessIdProperty.ProgrammaticName] =
ValueMatchers[AutomationElement.NameProperty.ProgrammaticName] = (information, value) => information.Name.Equals(value);
ValueMatchers[AutomationElement.AutomationIdProperty.ProgrammaticName] = (information, value) => information.AutomationId.Equals(value);
ValueMatchers[AutomationElement.ClassNameProperty.ProgrammaticName] = (information, value) => information.ClassName.Equals(value);
ValueMatchers[AutomationElement.ProcessIdProperty.ProgrammaticName] =
(information, value) => information.ProcessId.ToString().Equals(value.ToString());
valueMatchers[AutomationElement.ControlTypeProperty.ProgrammaticName] = (information, value) => information.ControlType.Id.Equals(value);
ValueMatchers[AutomationElement.ControlTypeProperty.ProgrammaticName] = (information, value) => information.ControlType.Id.Equals(value);
}

public AutomationSearchCondition(Condition condition)
Expand Down Expand Up @@ -132,7 +132,7 @@ private bool Satisfies(AutomationElement element, Condition[] testConditions, bo

if (condition is PropertyCondition)
{
var match = valueMatchers[((PropertyCondition) condition).Property.ProgrammaticName](element.Current, ((PropertyCondition) condition).Value);
var match = ValueMatchers[((PropertyCondition) condition).Property.ProgrammaticName](element.Current, ((PropertyCondition) condition).Value);
if (!match && and) return false;
if (match && !and) return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Automation;
Expand All @@ -10,6 +11,7 @@ public class DescendantFinder : IDescendantFinder

public DescendantFinder(AutomationElement automationElement)
{
if (automationElement == null) throw new ArgumentNullException("automationElement");
this.automationElement = automationElement;
}

Expand All @@ -25,7 +27,7 @@ public virtual AutomationElement Descendant(Condition condition)

public virtual List<AutomationElement> Descendants(AutomationSearchCondition automationSearchCondition)
{
AutomationElementCollection collection = automationElement.FindAll(TreeScope.Descendants, automationSearchCondition.Condition);
var collection = automationElement.FindAll(TreeScope.Descendants, automationSearchCondition.Condition);
var enumerable = collection.Cast<AutomationElement>();
return new List<AutomationElement>(enumerable);
}
Expand Down

0 comments on commit ea018b5

Please sign in to comment.