This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
TestStrategy.cs
122 lines (113 loc) · 4.12 KB
/
TestStrategy.cs
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
using Interop.UIAutomationCore;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.Edge.A11y
{
/// <summary>
/// A strategy for testing Edge Accessibility as scored at
/// http://html5accessibility.com/
/// </summary>
internal abstract class TestStrategy
{
protected DriverManager _driverManager;
protected string _RepositoryPath;
protected string _FileSuffix;
private string BuildTestUrl(string testName)
{
return _RepositoryPath + testName;
}
/// <summary>
/// This method is pretty minimal, most of the work is done in the
/// DefaultTestCase method below.
/// </summary>
/// <param name="testData">An object that describes the test</param>
/// <returns></returns>
public IEnumerable<TestCaseResult> Execute(TestData testData)
{
_driverManager.NavigateToUrl(BuildTestUrl(testData.TestName + _FileSuffix));
return TestElement(testData);
}
/// <summary>
/// This handles most of the work of the test cases.
///
/// N.B. all the test case results are returned in pairs, since we need to be
/// able to give half scores for certain results.
/// </summary>
/// <param name="testData">An object which stores information about the
/// expected results</param>
/// <param name="driverManager"></param>
/// <returns></returns>
internal abstract IEnumerable<TestCaseResult> TestElement(TestData testData);
/// <summary>
/// This wrapper is used to report 100% for a test
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
protected List<TestCaseResult> Pass(string name)
{
return new List<TestCaseResult> {
new TestCaseResult{
Result = ResultType.Pass,
Name = name + "-1",
},
new TestCaseResult{
Result = ResultType.Pass,
Name = name + "-2"
}
};
}
/// <summary>
/// This wrapper is used to report 0% for a test
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
protected List<TestCaseResult> Fail(string name, string cause)
{
return new List<TestCaseResult> {
new TestCaseResult{
Result = ResultType.Fail,
Name = name + "-1",
MoreInfo = cause
},
new TestCaseResult{
Result = ResultType.Fail,
Name = name + "-2",
MoreInfo = cause
}
};
}
/// <summary>
/// This wrapper is used to report 50% for a test
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
protected List<TestCaseResult> Half(string name, string cause)
{
return new List<TestCaseResult> {
new TestCaseResult{
Result = ResultType.Pass,
Name = name + "-1"
},
new TestCaseResult{
Result = ResultType.Fail,
Name = name + "-2",
MoreInfo = cause
}
};
}
/// <summary>
/// This is used to skip a test without influencing the overall score
/// </summary>
/// <param name="testName"></param>
/// <returns></returns>
protected IEnumerable<TestCaseResult> Skip(string testName)
{
return Enumerable.Empty<TestCaseResult>();
}
internal void Close()
{
_driverManager.Close();
}
}
}