-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
TouchScroll.cs
146 lines (130 loc) · 5.96 KB
/
TouchScroll.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//******************************************************************************
//
// Copyright (c) 2016 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;
namespace WebDriverAPI
{
[TestClass]
public class TouchScroll : AlarmClockBase
{
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context);
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown();
}
[TestMethod]
public void TouchScroll_Arbitrary()
{
// Different Alarm & Clock application version uses different UI elements
if (AlarmTabClassName == "ListViewItem")
{
// The latest Alarms & Clock application no longer has horizontal scroll UI elements
}
else
{
var alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
var stopwatchPivotItem = session.FindElementByAccessibilityId(StopwatchTabAutomationId);
Assert.IsNotNull(alarmPivotItem);
Assert.IsNotNull(stopwatchPivotItem);
Assert.IsTrue(alarmPivotItem.Selected);
Assert.IsFalse(stopwatchPivotItem.Selected);
// Perform scroll right touch action to switch from Alarm tab to Stopwatch tab
touchScreen.Scroll(100, 0);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsFalse(alarmPivotItem.Selected);
Assert.IsTrue(stopwatchPivotItem.Selected);
// Perform scroll left touch action to scroll back from Stopwatch tab to Alarm tab
touchScreen.Scroll(-100, 0);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsTrue(alarmPivotItem.Selected);
Assert.IsFalse(stopwatchPivotItem.Selected);
}
}
[TestMethod]
public void TouchScrollOnElement_Horizontal()
{
// Different Alarm & Clock application version uses different UI elements
if (AlarmTabClassName == "ListViewItem")
{
// The latest Alarms & Clock application no longer has horizontal scroll UI elements
}
else
{
var homePagePivot = session.FindElementByAccessibilityId("HomePagePivot");
var alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
var worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
Assert.IsNotNull(homePagePivot);
Assert.IsNotNull(alarmPivotItem);
Assert.IsNotNull(worldClockPivotItem);
Assert.IsTrue(alarmPivotItem.Selected);
Assert.IsFalse(worldClockPivotItem.Selected);
// Perform scroll left touch action to switch from Alarm tab to WorldClock tab
touchScreen.Scroll(homePagePivot.Coordinates, -100, 0);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsFalse(alarmPivotItem.Selected);
Assert.IsTrue(worldClockPivotItem.Selected);
// Perform scroll right touch action to scroll back from WorldClock tab to Alarm tab
touchScreen.Scroll(homePagePivot.Coordinates, 100, 0);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsTrue(alarmPivotItem.Selected);
Assert.IsFalse(worldClockPivotItem.Selected);
}
}
[TestMethod]
public void TouchScrollOnElement_Vertical()
{
// Navigate to add alarm page
session.FindElementByAccessibilityId("AddAlarmButton").Click();
session.FindElementByAccessibilityId("AlarmTimePicker").Click();
Thread.Sleep(TimeSpan.FromSeconds(1));
var minuteSelector = session.FindElementByAccessibilityId("MinuteLoopingSelector");
var minute00 = session.FindElementByName("00");
Assert.IsNotNull(minuteSelector);
Assert.IsNotNull(minute00);
Assert.IsTrue(minute00.Displayed);
// Perform scroll down touch action to scroll the minute hiding 00 minutes that was shown
touchScreen.Scroll(minuteSelector.Coordinates, 0, -55);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsFalse(minute00.Displayed);
// Perform scroll up touch action to scroll the the minute back showing 00 minutes that was hidden
touchScreen.Scroll(minuteSelector.Coordinates, 0, 55);
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsTrue(minute00.Displayed);
// Dismiss add alarm page
DismissAddAlarmPage();
}
[TestMethod]
public void TouchScrollOnElementError_StaleElement()
{
try
{
// Perform double tap touch on stale element
touchScreen.Scroll(GetStaleElement().Coordinates, 0, 100);
Assert.Fail("Exception should have been thrown");
}
catch (InvalidOperationException exception)
{
Assert.AreEqual(ErrorStrings.StaleElementReference, exception.Message);
}
}
}
}