-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathTableCellFactory.cs
More file actions
39 lines (36 loc) · 1.71 KB
/
TableCellFactory.cs
File metadata and controls
39 lines (36 loc) · 1.71 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
using System;
using System.Collections.Generic;
using System.Windows.Automation;
using TestStack.White.AutomationElementSearch;
using TestStack.White.Configuration;
using TestStack.White.UIItems.Actions;
using TestStack.White.UIItems.TableItems;
namespace TestStack.White.Factory
{
public class TableCellFactory
{
private readonly AutomationElement tableElement;
private readonly IActionListener actionListener;
private List<AutomationElement> customControlTypes;
public TableCellFactory(AutomationElement tableElement, IActionListener actionListener)
{
this.tableElement = tableElement;
this.actionListener = actionListener;
}
public virtual TableCells CreateCells(TableHeader tableHeader, AutomationElement rowElement)
{
if (customControlTypes == null)
customControlTypes = new AutomationElementFinder(tableElement).Descendants(AutomationSearchCondition.ByControlType(ControlType.DataItem));
string rowNameSuffix = " " + rowElement.Current.Name;
Predicate<AutomationElement> cellPredicate = element =>
{
string name = element.Current.Name;
return name.EndsWith(rowNameSuffix);
};
List<AutomationElement> tableCellElements = customControlTypes.FindAll(cellPredicate);
if (tableCellElements.Count > 0) return new TableCells(tableCellElements, tableHeader, actionListener);
tableCellElements = new AutomationElementFinder(rowElement).Descendants(AutomationSearchCondition.ByControlType(ControlType.DataItem));
return new TableCells(tableCellElements, tableHeader, actionListener);
}
}
}