-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathUIItemCollection.cs
More file actions
61 lines (54 loc) · 2.47 KB
/
UIItemCollection.cs
File metadata and controls
61 lines (54 loc) · 2.47 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Automation;
using Castle.Core.Logging;
using TestStack.White.Configuration;
using TestStack.White.Factory;
using TestStack.White.Mappings;
using TestStack.White.UIA;
using TestStack.White.UIItems.Actions;
namespace TestStack.White.UIItems
{
public class UIItemCollection : List<IUIItem>
{
private static readonly DictionaryMappedItemFactory DictionaryMappedItemFactory = new DictionaryMappedItemFactory();
private readonly ILogger logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(UIItemCollection));
public UIItemCollection(params UIItem[] uiItems)
{
AddRange(uiItems);
}
public UIItemCollection(IEnumerable entities) : base(entities.OfType<IUIItem>()) {}
public UIItemCollection(IEnumerable<AutomationElement> automationElements, IActionListener actionListener)
: this(automationElements, DictionaryMappedItemFactory, actionListener) {}
public UIItemCollection(IEnumerable automationElements, IActionListener actionListener)
: this(automationElements, DictionaryMappedItemFactory, actionListener) {}
public UIItemCollection(IEnumerable automationElements, IUIItemFactory uiItemFactory, IActionListener actionListener)
{
foreach (AutomationElement automationElement in automationElements)
{
IUIItem uiItem = uiItemFactory.Create(automationElement, actionListener);
if (uiItem != null) Add(uiItem);
}
}
public UIItemCollection(IEnumerable automationElements, IActionListener actionListener, Type customItemType)
{
foreach (AutomationElement automationElement in automationElements)
{
try
{
if (!automationElement.IsPrimaryControl()) continue;
var uiItem = DictionaryMappedItemFactory.Create(automationElement, actionListener, customItemType);
if (uiItem != null) Add(uiItem);
}
catch (ControlDictionaryException e)
{
//Printing the Bease exception message...
logger.Warn(e.GetBaseException().Message);
logger.WarnFormat("Couldn't create UIItem for AutomationElement, {0}", automationElement.Display());
}
}
}
}
}