Skip to content

Commit ea018b5

Browse files
author
Jake Ginnivan
committed
Trying to track down this null reference exeception
1 parent 83e9eec commit ea018b5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/TestStack.White/AutomationElementSearch/AutomationSearchCondition.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ namespace TestStack.White.AutomationElementSearch
77
{
88
public class AutomationSearchCondition
99
{
10-
private readonly List<Condition> conditions = new List<Condition>();
11-
private static readonly Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>> valueMatchers =
10+
static readonly Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>> ValueMatchers =
1211
new Dictionary<string, Func<AutomationElement.AutomationElementInformation, object, bool>>();
12+
readonly List<Condition> conditions = new List<Condition>();
1313

1414
static AutomationSearchCondition()
1515
{
16-
valueMatchers[AutomationElement.NameProperty.ProgrammaticName] = (information, value) => information.Name.Equals(value);
17-
valueMatchers[AutomationElement.AutomationIdProperty.ProgrammaticName] = (information, value) => information.AutomationId.Equals(value);
18-
valueMatchers[AutomationElement.ClassNameProperty.ProgrammaticName] = (information, value) => information.ClassName.Equals(value);
19-
valueMatchers[AutomationElement.ProcessIdProperty.ProgrammaticName] =
16+
ValueMatchers[AutomationElement.NameProperty.ProgrammaticName] = (information, value) => information.Name.Equals(value);
17+
ValueMatchers[AutomationElement.AutomationIdProperty.ProgrammaticName] = (information, value) => information.AutomationId.Equals(value);
18+
ValueMatchers[AutomationElement.ClassNameProperty.ProgrammaticName] = (information, value) => information.ClassName.Equals(value);
19+
ValueMatchers[AutomationElement.ProcessIdProperty.ProgrammaticName] =
2020
(information, value) => information.ProcessId.ToString().Equals(value.ToString());
21-
valueMatchers[AutomationElement.ControlTypeProperty.ProgrammaticName] = (information, value) => information.ControlType.Id.Equals(value);
21+
ValueMatchers[AutomationElement.ControlTypeProperty.ProgrammaticName] = (information, value) => information.ControlType.Id.Equals(value);
2222
}
2323

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

133133
if (condition is PropertyCondition)
134134
{
135-
var match = valueMatchers[((PropertyCondition) condition).Property.ProgrammaticName](element.Current, ((PropertyCondition) condition).Value);
135+
var match = ValueMatchers[((PropertyCondition) condition).Property.ProgrammaticName](element.Current, ((PropertyCondition) condition).Value);
136136
if (!match && and) return false;
137137
if (match && !and) return true;
138138
}

src/TestStack.White/AutomationElementSearch/DescendantFinder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using System.Windows.Automation;
@@ -10,6 +11,7 @@ public class DescendantFinder : IDescendantFinder
1011

1112
public DescendantFinder(AutomationElement automationElement)
1213
{
14+
if (automationElement == null) throw new ArgumentNullException("automationElement");
1315
this.automationElement = automationElement;
1416
}
1517

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

2628
public virtual List<AutomationElement> Descendants(AutomationSearchCondition automationSearchCondition)
2729
{
28-
AutomationElementCollection collection = automationElement.FindAll(TreeScope.Descendants, automationSearchCondition.Condition);
30+
var collection = automationElement.FindAll(TreeScope.Descendants, automationSearchCondition.Condition);
2931
var enumerable = collection.Cast<AutomationElement>();
3032
return new List<AutomationElement>(enumerable);
3133
}

0 commit comments

Comments
 (0)