-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathTableRowFactory.cs
More file actions
59 lines (49 loc) · 1.83 KB
/
TableRowFactory.cs
File metadata and controls
59 lines (49 loc) · 1.83 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
using System.Collections.Generic;
using System.Windows.Automation;
using TestStack.White.AutomationElementSearch;
using TestStack.White.UIItems.Actions;
using TestStack.White.UIItems.TableItems;
namespace TestStack.White.Factory
{
public class TableRowFactory
{
private readonly AutomationElementFinder automationElementFinder;
public TableRowFactory(AutomationElementFinder automationElementFinder)
{
this.automationElementFinder = automationElementFinder;
}
public virtual int NumberOfRows
{
get { return GetRowElements().Count; }
}
public virtual TableRows CreateRows(IActionListener actionListener, TableHeader tableHeader)
{
var rowElements = GetRowElements();
return new TableRows(rowElements, actionListener, tableHeader, new TableCellFactory(automationElementFinder.AutomationElement, actionListener));
}
private List<AutomationElement> GetRowElements()
{
// this will find only first level children of out element - rows
var descendants = automationElementFinder.Children(AutomationSearchCondition.ByControlType(ControlType.Custom));
var automationElements = new List<AutomationElement>(descendants.FindAll(IsRow));
return automationElements;
}
private static bool IsRow(AutomationElement element)
{
var parts = element.Current.Name.Split(' ');
if (parts.Length < 2)
{
return false;
}
int result;
for (var i = parts.Length - 1; i >= 0; i--)
{
if (int.TryParse(parts[i], out result))
{
return true;
}
}
return false;
}
}
}