-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathScreenItem.cs
More file actions
89 lines (76 loc) · 3.99 KB
/
ScreenItem.cs
File metadata and controls
89 lines (76 loc) · 3.99 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
using System;
using System.Windows.Automation;
using Castle.Core.Logging;
using TestStack.White.Configuration;
using TestStack.White.Utility;
namespace TestStack.White.UIItems.Scrolling
{
public class ScreenItem
{
private readonly UIItem uiItem;
private readonly IVScrollBar verticalScroll;
private readonly ILogger logger = CoreAppXmlConfiguration.Instance.LoggerFactory.Create(typeof(ScreenItem));
public ScreenItem(UIItem uiItem, IScrollBars scrollBars)
{
this.uiItem = uiItem;
if (scrollBars == null || scrollBars.Vertical == null) return;
verticalScroll = scrollBars.Vertical;
}
internal virtual void MakeVisible(VerticalSpanProvider verticalSpanProvider)
{
VerticalSpan verticalSpan = verticalSpanProvider.VerticalSpan;
if (verticalSpan.Contains(uiItem.Bounds))
{
logger.DebugFormat("UIItem ({0}) whose bounds are ({1}) is within bounds of parent whose vertical span is {2}", uiItem,
uiItem.Bounds, verticalSpan);
return;
}
if (verticalScroll != null && verticalScroll.IsScrollable)
{
logger.DebugFormat("Trying to make visible {0}, item's bounds are {1} and parent's span is {2}", uiItem, uiItem.Bounds, verticalSpan);
if (verticalScroll.IsNotMinimum)
{
verticalScroll.SetToMinimum();
verticalSpan = verticalSpanProvider.VerticalSpan;
logger.DebugFormat("Scroll Position set to minimum value.");
}
if (verticalSpan.Contains(uiItem.Bounds))
{
logger.DebugFormat("UIItem ({0}) whose bounds are ({1}) is within bounds of parent whose vertical span is {2}", uiItem,
uiItem.Bounds, verticalSpan);
return;
}
var success = Retry.For(
() =>
{
verticalScroll.ScrollDownLarge();
var bounds = uiItem.Bounds;
const string messageFormat = "Trying to make {0} visible, item's bounds are {1} and parent's span is {2}";
logger.DebugFormat(messageFormat, uiItem, bounds, verticalSpan);
return verticalSpan.Contains(bounds);
}, CoreAppXmlConfiguration.Instance.BusyTimeout(), TimeSpan.FromMilliseconds(0));
if (!success)
throw new UIActionException(string.Format("Could not make the {0} visible{1}", uiItem, Constants.BusyMessage));
}
else if (verticalSpanProvider is UIItem)
{
var containerUiItem = (UIItem)verticalSpanProvider;
logger.DebugFormat("Trying to make visible {0}, item's bounds are {1} and parent's span is {2}", uiItem, uiItem.Bounds, verticalSpan);
var success = Retry.For(
() =>
{
if (uiItem.Bounds.Top + uiItem.Bounds.Bottom < verticalScroll.Bounds.Top + verticalScroll.Bounds.Bottom)
containerUiItem.MouseWheel(1);
else
containerUiItem.MouseWheel(-1);
var bounds = uiItem.Bounds;
const string messageFormat = "Trying to make {0} visible, item's bounds are {1} and parent's span is {2}";
logger.DebugFormat(messageFormat, uiItem, bounds, verticalSpan);
return verticalSpan.Contains(bounds);
}, CoreAppXmlConfiguration.Instance.BusyTimeout(), TimeSpan.FromMilliseconds(0));
if (!success)
throw new UIActionException(string.Format("Could not make the {0} visible{1}", uiItem, Constants.BusyMessage));
}
}
}
}