forked from microsoft/WinAppDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatePicker.cs
151 lines (134 loc) · 6.84 KB
/
DatePicker.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
147
148
149
150
151
//******************************************************************************
//
// Copyright (c) 2017 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 OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium;
namespace UWPControls
{
[TestClass]
public class DatePicker : UWPControlsBase
{
private static WindowsElement datePickerElement1 = null;
private static WindowsElement datePickerElement2 = null;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context);
NavigateTo("Selection and picker controls", "DatePicker");
datePickerElement1 = session.FindElementByName("Pick a date");
Assert.IsNotNull(datePickerElement1);
datePickerElement2 = session.FindElementByAccessibilityId("Control2");
Assert.IsNotNull(datePickerElement2);
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown();
}
[TestMethod]
public void Click()
{
// Click datePickerElement1 to show the picker and simply dismiss it
datePickerElement1.Click();
var datePickerFlyout = session.FindElementByAccessibilityId("DatePickerFlyoutPresenter");
Assert.IsNotNull(datePickerFlyout);
Assert.IsTrue(datePickerFlyout.Displayed);
session.FindElementByAccessibilityId("DatePickerFlyoutPresenter").FindElementByAccessibilityId("DismissButton").Click();
System.Threading.Thread.Sleep(1000);
// Click datePickerElement1 to show the picker and set the year to 2000
datePickerElement1.Click();
datePickerFlyout = session.FindElementByAccessibilityId("DatePickerFlyoutPresenter");
Assert.IsNotNull(datePickerFlyout);
var yearLoopingSelector = datePickerFlyout.FindElementByAccessibilityId("YearLoopingSelector");
Assert.IsNotNull(yearLoopingSelector);
var currentYear = yearLoopingSelector.Text;
yearLoopingSelector.FindElementByName("2000").Click();
System.Threading.Thread.Sleep(1000);
Assert.AreNotEqual(currentYear, yearLoopingSelector.Text);
datePickerFlyout.FindElementByAccessibilityId("AcceptButton").Click();
}
[TestMethod]
public void Displayed()
{
Assert.IsTrue(datePickerElement1.Displayed);
Assert.IsTrue(datePickerElement2.Displayed);
}
[TestMethod]
public void Enabled()
{
Assert.IsTrue(datePickerElement1.Enabled);
Assert.IsTrue(datePickerElement2.Enabled);
}
[TestMethod]
public void Location()
{
Assert.IsTrue(datePickerElement2.Location.X >= datePickerElement1.Location.X);
Assert.IsTrue(datePickerElement2.Location.Y >= datePickerElement1.Location.Y);
}
[TestMethod]
public void LocationInView()
{
Assert.IsTrue(datePickerElement2.LocationOnScreenOnceScrolledIntoView.X >= datePickerElement1.LocationOnScreenOnceScrolledIntoView.X);
Assert.IsTrue(datePickerElement2.LocationOnScreenOnceScrolledIntoView.Y >= datePickerElement1.LocationOnScreenOnceScrolledIntoView.Y);
}
[TestMethod]
public void Name()
{
Assert.AreEqual("ControlType.Group", datePickerElement1.TagName);
Assert.AreEqual("ControlType.Group", datePickerElement2.TagName);
}
[TestMethod]
public void SendKeys()
{
datePickerElement1.SendKeys(Keys.Space);
var datePickerFlyout = session.FindElementByAccessibilityId("DatePickerFlyoutPresenter");
var day = datePickerFlyout.FindElementByAccessibilityId("DayLoopingSelector").Text;
var month = datePickerFlyout.FindElementByAccessibilityId("MonthLoopingSelector").Text;
var year = datePickerFlyout.FindElementByAccessibilityId("YearLoopingSelector").Text;
// Alter the DatePicker entries using key presses
datePickerFlyout.SendKeys(Keys.Up + Keys.Right + Keys.Down + Keys.Right + Keys.Up);
Assert.AreNotEqual(day, datePickerFlyout.FindElementByAccessibilityId("DayLoopingSelector").Text);
Assert.AreNotEqual(month, datePickerFlyout.FindElementByAccessibilityId("MonthLoopingSelector").Text);
Assert.AreNotEqual(year, datePickerFlyout.FindElementByAccessibilityId("YearLoopingSelector").Text);
datePickerFlyout.SendKeys(Keys.Enter);
// Restore the DatePicker to original value. Note that datePickerFlyout needs to be looked up again after dismissal
datePickerElement1.SendKeys(Keys.Space);
datePickerFlyout = session.FindElementByAccessibilityId("DatePickerFlyoutPresenter");
datePickerFlyout.SendKeys(Keys.Down + Keys.Right + Keys.Up + Keys.Right + Keys.Down);
Assert.AreEqual(day, datePickerFlyout.FindElementByAccessibilityId("DayLoopingSelector").Text);
Assert.AreEqual(month, datePickerFlyout.FindElementByAccessibilityId("MonthLoopingSelector").Text);
Assert.AreEqual(year, datePickerFlyout.FindElementByAccessibilityId("YearLoopingSelector").Text);
datePickerFlyout.SendKeys(Keys.Enter);
}
[TestMethod]
public void Size()
{
Assert.IsTrue(datePickerElement1.Size.Width > 0);
Assert.IsTrue(datePickerElement1.Size.Height > 0);
Assert.IsTrue(datePickerElement2.Size.Width >= datePickerElement1.Size.Width);
Assert.IsTrue(datePickerElement2.Size.Height <= datePickerElement1.Size.Height);
}
[TestMethod]
public void Text()
{
datePickerElement2.Click();
var datePickerFlyout = session.FindElementByAccessibilityId("DatePickerFlyoutPresenter");
Assert.AreNotEqual(string.Empty, datePickerFlyout.FindElementByAccessibilityId("DayLoopingSelector").Text);
Assert.AreNotEqual(string.Empty, datePickerFlyout.FindElementByAccessibilityId("MonthLoopingSelector").Text);
datePickerFlyout.FindElementByAccessibilityId("DismissButton").Click();
}
}
}