-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathAutomationSearchConditionTests.cs
More file actions
155 lines (151 loc) · 6.96 KB
/
AutomationSearchConditionTests.cs
File metadata and controls
155 lines (151 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using NUnit.Framework;
using System.Windows.Automation;
using TestStack.White.AutomationElementSearch;
using TestStack.White.UIItems;
using TestStack.White.UIItems.ListBoxItems;
namespace TestStack.White.UITests.AutomationElementSearch
{
[TestFixture(WindowsFramework.WinForms)]
[TestFixture(WindowsFramework.Wpf)]
public class AutomationSearchConditionTests : WhiteUITestBase
{
public AutomationSearchConditionTests(WindowsFramework framework)
: base(framework)
{
}
[Test]
public void BothOrConditionsAreFalseTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("X").Condition,
AutomationSearchCondition.ByName("X").Condition);
var bothOrConditionsAreFalse = new AutomationSearchCondition(twoConditions);
bool result = bothOrConditionsAreFalse.Satisfies(button.AutomationElement);
Assert.That(result, Is.False);
}
[Test]
public void FirstOrConditionIsTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("ButtonWithTooltip").Condition,
AutomationSearchCondition.ByName("X").Condition);
var firstOrConditionIsTrue = new AutomationSearchCondition(twoConditions);
bool result = firstOrConditionIsTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.True);
}
[Test]
public void SecondOrConditionIsTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("X").Condition,
AutomationSearchCondition.ByName("Button with Tooltip").Condition);
var secondOrConditionIsTrue = new AutomationSearchCondition(twoConditions);
bool result = secondOrConditionIsTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.True);
}
[Test]
public void BothOrConditionsAreTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("ButtonWithTooltip").Condition,
AutomationSearchCondition.ByName("Button with Tooltip").Condition);
var bothOrConditionsAreTrue = new AutomationSearchCondition(twoConditions);
bool result = bothOrConditionsAreTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.True);
}
[Test]
public void BothAndConditionsAreFalseTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new AndCondition(
AutomationSearchCondition.ByAutomationId("X").Condition,
AutomationSearchCondition.ByName("X").Condition);
var bothOrConditionsAreFalse = new AutomationSearchCondition(twoConditions);
bool result = bothOrConditionsAreFalse.Satisfies(button.AutomationElement);
Assert.That(result, Is.False);
}
[Test]
public void FirstAndConditionIsTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new AndCondition(
AutomationSearchCondition.ByAutomationId("ButtonWithTooltip").Condition,
AutomationSearchCondition.ByName("X").Condition);
var firstAndConditionIsTrue = new AutomationSearchCondition(twoConditions);
bool result = firstAndConditionIsTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.False);
}
[Test]
public void SecondAndConditionIsTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new AndCondition(
AutomationSearchCondition.ByAutomationId("X").Condition,
AutomationSearchCondition.ByName("Button with Tooltip").Condition);
var secondAndConditionIsTrue = new AutomationSearchCondition(twoConditions);
bool result = secondAndConditionIsTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.False);
}
[Test]
public void BothAndConditionsAreTrueTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var twoConditions = new AndCondition(
AutomationSearchCondition.ByAutomationId("ButtonWithTooltip").Condition,
AutomationSearchCondition.ByName("Button with Tooltip").Condition);
var bothAndConditionsAreTrue = new AutomationSearchCondition(twoConditions);
bool result = bothAndConditionsAreTrue.Satisfies(button.AutomationElement);
Assert.That(result, Is.True);
}
[Test]
public void ComplexOrConditionTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var comboBox = MainWindow.Get<ComboBox>("EditableComboBox");
var listBox = MainWindow.Get<ListBox>("ListBoxWithVScrollBar");
var checkedListBox = MainWindow.Get<ListBox>("CheckedListBox");
var typeConditions = new OrCondition(
AutomationSearchCondition.ByControlType(ControlType.Image).Condition,
AutomationSearchCondition.ByControlType(ControlType.List).Condition);
var nameOrIdConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("EditableComboBox").Condition,
AutomationSearchCondition.ByName("CheckedListBoxTests").Condition);
var complexOrCondition = new AutomationSearchCondition(new OrCondition(typeConditions, nameOrIdConditions));
bool resultForButton = complexOrCondition.Satisfies(button.AutomationElement);
bool resultForComboBox = complexOrCondition.Satisfies(comboBox.AutomationElement);
bool resultForListBox = complexOrCondition.Satisfies(listBox.AutomationElement);
bool resultForCheckedListBox = complexOrCondition.Satisfies(checkedListBox.AutomationElement);
Assert.That(resultForButton, Is.False);
Assert.That(resultForComboBox, Is.True);
Assert.That(resultForListBox, Is.True);
Assert.That(resultForCheckedListBox, Is.True);
}
[Test]
public void ComplexAndConditionTest()
{
var button = MainWindow.Get<Button>("ButtonWithTooltip");
var comboBox = MainWindow.Get<ComboBox>("EditableComboBox");
var listBox = MainWindow.Get<ListBox>("ListBoxWithVScrollBar");
var checkedListBox = MainWindow.Get<ListBox>("CheckedListBox");
var typeConditions = new OrCondition(
AutomationSearchCondition.ByControlType(ControlType.Button).Condition,
AutomationSearchCondition.ByControlType(ControlType.ComboBox).Condition);
var nameOrIdConditions = new OrCondition(
AutomationSearchCondition.ByAutomationId("ListBoxWithVScrollBar").Condition,
AutomationSearchCondition.ByName("Button with Tooltip").Condition);
var complexAndCondition = new AutomationSearchCondition(new AndCondition(typeConditions, nameOrIdConditions));
bool resultForButton = complexAndCondition.Satisfies(button.AutomationElement);
bool resultForComboBox = complexAndCondition.Satisfies(comboBox.AutomationElement);
bool resultForListBox = complexAndCondition.Satisfies(listBox.AutomationElement);
bool resultForCheckedListBox = complexAndCondition.Satisfies(checkedListBox.AutomationElement);
Assert.That(resultForButton, Is.True);
Assert.That(resultForComboBox, Is.False);
Assert.That(resultForListBox, Is.False);
Assert.That(resultForCheckedListBox, Is.False);
}
}
}