Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8df9ce

Browse files
committed
Update WebDriverAPI tests to support the latest Alarms & Clock and Calculator apps
Temporarily bypass the following test scenarios until they can be replaced: - ActionsPen.Pen_Scroll_Horizontal - ActionsTouch.Touch_Scroll_Horizontal - ElementClear.ClearElementError_ElementNotVisible - ElementClick.ClickElementError_ElementNotVisible - ElementSendKeys.SendKeysToElementError_ElementNotVisible - TouchScroll.TouchScroll_Arbitrary - TouchScroll.TouchScrollOnElement_Horizontal
1 parent 3ac76da commit a8df9ce

22 files changed

+494
-245
lines changed

Tests/WebDriverAPI/ActionsPen.cs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public void Pen_Click_BarrelButton()
7979
[TestMethod]
8080
public void Pen_Click_OriginElement()
8181
{
82-
var alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
83-
var worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
82+
var alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
83+
var worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
8484
Assert.IsNotNull(alarmPivotItem);
8585
Assert.IsNotNull(worldClockPivotItem);
8686
Assert.IsTrue(alarmPivotItem.Selected);
@@ -113,8 +113,8 @@ public void Pen_Click_OriginElement()
113113
[TestMethod]
114114
public void Pen_Click_OriginPointer()
115115
{
116-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
117-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
116+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
117+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
118118
int relativeX = 0; // Initial x coordinate
119119
int relativeY = 0; // Initial y coordinate
120120
Assert.IsNotNull(alarmPivotItem);
@@ -153,8 +153,8 @@ public void Pen_Click_OriginPointer()
153153
[TestMethod]
154154
public void Pen_Click_OriginViewport()
155155
{
156-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
157-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
156+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
157+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
158158
int x = worldClockPivotItem.Location.X; // x coordinate of UI element relative to application window
159159
int y = worldClockPivotItem.Location.Y; // y coordinate of UI element relative to application window
160160
Assert.IsNotNull(alarmPivotItem);
@@ -320,39 +320,47 @@ public void Pen_LongClick()
320320
[TestMethod]
321321
public void Pen_Scroll_Horizontal()
322322
{
323-
WindowsElement homePagePivot = session.FindElementByAccessibilityId("HomePagePivot");
324-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
325-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
326-
Assert.IsNotNull(homePagePivot);
327-
Assert.IsNotNull(alarmPivotItem);
328-
Assert.IsNotNull(worldClockPivotItem);
329-
Assert.IsTrue(alarmPivotItem.Selected);
330-
Assert.IsFalse(worldClockPivotItem.Selected);
331-
332-
// Perform scroll left pen action to switch from Alarm to WorldClock tab
333-
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
334-
ActionSequence sequence = new ActionSequence(penDevice, 0);
335-
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
336-
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
337-
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, -session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
338-
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
339-
session.PerformActions(new List<ActionSequence> { sequence });
340-
341-
Thread.Sleep(TimeSpan.FromSeconds(1));
342-
Assert.IsFalse(alarmPivotItem.Selected);
343-
Assert.IsTrue(worldClockPivotItem.Selected);
344-
345-
// Perform scroll right pen action to switch back from WorldClock to Alarm tab
346-
sequence = new ActionSequence(penDevice, 0);
347-
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
348-
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
349-
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
350-
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
351-
session.PerformActions(new List<ActionSequence> { sequence });
352-
353-
Thread.Sleep(TimeSpan.FromSeconds(1));
354-
Assert.IsTrue(alarmPivotItem.Selected);
355-
Assert.IsFalse(worldClockPivotItem.Selected);
323+
// Different Alarm & Clock application version uses different UI elements
324+
if (AlarmTabClassName == "ListViewItem")
325+
{
326+
// The latest Alarms & Clock application no longer has horizontal scroll UI elements
327+
}
328+
else
329+
{
330+
WindowsElement homePagePivot = session.FindElementByAccessibilityId("HomePagePivot");
331+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
332+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
333+
Assert.IsNotNull(homePagePivot);
334+
Assert.IsNotNull(alarmPivotItem);
335+
Assert.IsNotNull(worldClockPivotItem);
336+
Assert.IsTrue(alarmPivotItem.Selected);
337+
Assert.IsFalse(worldClockPivotItem.Selected);
338+
339+
// Perform scroll left pen action to switch from Alarm to WorldClock tab
340+
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
341+
ActionSequence sequence = new ActionSequence(penDevice, 0);
342+
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
343+
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
344+
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, -session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
345+
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
346+
session.PerformActions(new List<ActionSequence> { sequence });
347+
348+
Thread.Sleep(TimeSpan.FromSeconds(1));
349+
Assert.IsFalse(alarmPivotItem.Selected);
350+
Assert.IsTrue(worldClockPivotItem.Selected);
351+
352+
// Perform scroll right pen action to switch back from WorldClock to Alarm tab
353+
sequence = new ActionSequence(penDevice, 0);
354+
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
355+
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
356+
sequence.AddAction(penDevice.CreatePointerMove(homePagePivot, session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
357+
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
358+
session.PerformActions(new List<ActionSequence> { sequence });
359+
360+
Thread.Sleep(TimeSpan.FromSeconds(1));
361+
Assert.IsTrue(alarmPivotItem.Selected);
362+
Assert.IsFalse(worldClockPivotItem.Selected);
363+
}
356364
}
357365

358366
[TestMethod]

Tests/WebDriverAPI/ActionsTouch.cs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public static void ClassCleanup()
4949
[TestMethod]
5050
public void Touch_Click_OriginElement()
5151
{
52-
var alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
53-
var worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
52+
var alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
53+
var worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
5454
Assert.IsNotNull(alarmPivotItem);
5555
Assert.IsNotNull(worldClockPivotItem);
5656
Assert.IsTrue(alarmPivotItem.Selected);
@@ -83,8 +83,8 @@ public void Touch_Click_OriginElement()
8383
[TestMethod]
8484
public void Touch_Click_OriginPointer()
8585
{
86-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
87-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
86+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
87+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
8888
int relativeX = 0; // Initial x coordinate
8989
int relativeY = 0; // Initial y coordinate
9090
Assert.IsNotNull(alarmPivotItem);
@@ -123,8 +123,8 @@ public void Touch_Click_OriginPointer()
123123
[TestMethod]
124124
public void Touch_Click_OriginViewport()
125125
{
126-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
127-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
126+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
127+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
128128
int x = worldClockPivotItem.Location.X; // x coordinate of UI element relative to application window
129129
int y = worldClockPivotItem.Location.Y; // y coordinate of UI element relative to application window
130130
Assert.IsNotNull(alarmPivotItem);
@@ -290,39 +290,47 @@ public void Touch_LongClick()
290290
[TestMethod]
291291
public void Touch_Scroll_Horizontal()
292292
{
293-
WindowsElement homePagePivot = session.FindElementByAccessibilityId("HomePagePivot");
294-
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId("AlarmPivotItem");
295-
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId("WorldClockPivotItem");
296-
Assert.IsNotNull(homePagePivot);
297-
Assert.IsNotNull(alarmPivotItem);
298-
Assert.IsNotNull(worldClockPivotItem);
299-
Assert.IsTrue(alarmPivotItem.Selected);
300-
Assert.IsFalse(worldClockPivotItem.Selected);
301-
302-
// Perform scroll left touch action to switch from Alarm to WorldClock tab
303-
PointerInputDevice touchDevice = new PointerInputDevice(PointerKind.Touch);
304-
ActionSequence sequence = new ActionSequence(touchDevice, 0);
305-
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
306-
sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
307-
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, -session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
308-
sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
309-
session.PerformActions(new List<ActionSequence> { sequence });
310-
311-
Thread.Sleep(TimeSpan.FromSeconds(1));
312-
Assert.IsFalse(alarmPivotItem.Selected);
313-
Assert.IsTrue(worldClockPivotItem.Selected);
314-
315-
// Perform scroll right touch action to switch back from WorldClock to Alarm tab
316-
sequence = new ActionSequence(touchDevice, 0);
317-
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
318-
sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
319-
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
320-
sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
321-
session.PerformActions(new List<ActionSequence> { sequence });
322-
323-
Thread.Sleep(TimeSpan.FromSeconds(1));
324-
Assert.IsTrue(alarmPivotItem.Selected);
325-
Assert.IsFalse(worldClockPivotItem.Selected);
293+
// Different Alarm & Clock application version uses different UI elements
294+
if (AlarmTabClassName == "ListViewItem")
295+
{
296+
// The latest Alarms & Clock application no longer has horizontal scroll UI elements
297+
}
298+
else
299+
{
300+
WindowsElement homePagePivot = session.FindElementByAccessibilityId("HomePagePivot");
301+
WindowsElement alarmPivotItem = session.FindElementByAccessibilityId(AlarmTabAutomationId);
302+
WindowsElement worldClockPivotItem = session.FindElementByAccessibilityId(WorldClockTabAutomationId);
303+
Assert.IsNotNull(homePagePivot);
304+
Assert.IsNotNull(alarmPivotItem);
305+
Assert.IsNotNull(worldClockPivotItem);
306+
Assert.IsTrue(alarmPivotItem.Selected);
307+
Assert.IsFalse(worldClockPivotItem.Selected);
308+
309+
// Perform scroll left touch action to switch from Alarm to WorldClock tab
310+
PointerInputDevice touchDevice = new PointerInputDevice(PointerKind.Touch);
311+
ActionSequence sequence = new ActionSequence(touchDevice, 0);
312+
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
313+
sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
314+
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, -session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
315+
sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
316+
session.PerformActions(new List<ActionSequence> { sequence });
317+
318+
Thread.Sleep(TimeSpan.FromSeconds(1));
319+
Assert.IsFalse(alarmPivotItem.Selected);
320+
Assert.IsTrue(worldClockPivotItem.Selected);
321+
322+
// Perform scroll right touch action to switch back from WorldClock to Alarm tab
323+
sequence = new ActionSequence(touchDevice, 0);
324+
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, 0, 0, TimeSpan.Zero));
325+
sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
326+
sequence.AddAction(touchDevice.CreatePointerMove(homePagePivot, session.Manage().Window.Size.Width / 2, 0, TimeSpan.FromSeconds(.5)));
327+
sequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
328+
session.PerformActions(new List<ActionSequence> { sequence });
329+
330+
Thread.Sleep(TimeSpan.FromSeconds(1));
331+
Assert.IsTrue(alarmPivotItem.Selected);
332+
Assert.IsFalse(worldClockPivotItem.Selected);
333+
}
326334
}
327335

328336
[TestMethod]

Tests/WebDriverAPI/AppSessionBase/AlarmClockBase.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class AlarmClockBase
2828
protected static RemoteTouchScreen touchScreen;
2929
protected WindowsElement alarmTabElement;
3030

31+
// UI elements attributes that differ between Alarms & Clock versions
32+
protected string AlarmTabAutomationId;
33+
protected string AlarmTabClassName;
34+
protected string StopwatchTabAutomationId;
35+
protected string WorldClockTabAutomationId;
36+
3137
public static void Setup(TestContext context)
3238
{
3339
// Launch Alarms & Clock application if it is not yet launched
@@ -66,19 +72,37 @@ public virtual void TestInit()
6672
// Attempt to go back to the main page in case Alarms & Clock app is started in EditAlarm view
6773
try
6874
{
69-
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
75+
alarmTabElement = FindAlarmTabElement();
7076
}
7177
catch
7278
{
7379
DismissAddAlarmPage();
74-
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
80+
alarmTabElement = FindAlarmTabElement();
7581
}
7682

7783
Assert.IsNotNull(alarmTabElement);
7884
if (!alarmTabElement.Selected)
7985
{
8086
alarmTabElement.Click();
8187
}
88+
89+
// Different Alarm & Clock application version uses different UI elements
90+
if (alarmTabElement.GetAttribute("AutomationId") == "AlarmButton")
91+
{
92+
// Latest version of Alarms & Clock application
93+
AlarmTabClassName = "ListViewItem";
94+
AlarmTabAutomationId = "AlarmButton";
95+
StopwatchTabAutomationId = "StopwatchButton";
96+
WorldClockTabAutomationId = "ClockButton";
97+
}
98+
else
99+
{
100+
// Earlier version of Alarms & Clock application
101+
AlarmTabClassName = "PivotItem";
102+
AlarmTabAutomationId = "AlarmPivotItem";
103+
StopwatchTabAutomationId = "StopwatchPivotItem";
104+
WorldClockTabAutomationId = "WorldClockPivotItem";
105+
}
82106
}
83107

84108
protected void AddAlarmEntry(string alarmName)
@@ -110,7 +134,7 @@ protected void DeletePreviouslyCreatedAlarmEntry(string alarmName)
110134
protected void CreateStopwatchLapEntries(uint numberOfEntry)
111135
{
112136
// Navigate to Stopwatch tab
113-
var stopwatchPivotItem = session.FindElementByAccessibilityId("StopwatchPivotItem");
137+
var stopwatchPivotItem = session.FindElementByAccessibilityId(StopwatchTabAutomationId);
114138
stopwatchPivotItem.Click();
115139

116140
// Reset stopwatch
@@ -153,6 +177,24 @@ protected static void DismissAddAlarmPage()
153177
}
154178
}
155179

180+
protected static WindowsElement FindAlarmTabElement()
181+
{
182+
WindowsElement element;
183+
try
184+
{
185+
// The latest Alarms & Clock application uses a ListViewItem
186+
// with "AlarmButton" automation id as the alarm tab selector
187+
element = session.FindElementByAccessibilityId("AlarmButton");
188+
}
189+
catch (InvalidOperationException)
190+
{
191+
// The previous version of Alarms & Clock app uses a PivotItem with
192+
// "AlarmPivotItem" automation id as the alarm tab selector
193+
element = session.FindElementByAccessibilityId("AlarmPivotItem");
194+
}
195+
return element;
196+
}
197+
156198
protected static WindowsElement FindAppTitleBar()
157199
{
158200
WindowsElement element;

Tests/WebDriverAPI/AppSessionBase/CalculatorBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ public static void Setup(TestContext context)
5555
// Ensure that calculator is in standard mode
5656
if (!header.Text.Equals("Standard", StringComparison.OrdinalIgnoreCase))
5757
{
58-
session.FindElementByAccessibilityId("NavButton").Click();
58+
try
59+
{
60+
// Current version of Calculator application
61+
session.FindElementByAccessibilityId("TogglePaneButton").Click();
62+
}
63+
catch
64+
{
65+
// Previous version of Calculator application
66+
session.FindElementByAccessibilityId("NavButton").Click();
67+
}
68+
5969
Thread.Sleep(TimeSpan.FromSeconds(1));
6070
var splitViewPane = session.FindElementByClassName("SplitViewPane");
6171
splitViewPane.FindElementByName("Standard Calculator").Click();

0 commit comments

Comments
 (0)