Skip to content

Commit 5401fb3

Browse files
committed
Merged PR 1887339: Fix WebDriverAPI tests for updated Calculator and Alarm App.
Fix WebDriverAPI tests for updated Calculator and Alarm App. Dismiss save confirmation dialog in the alarms app. Update the way to find the title on the calculator app.
1 parent f3e17d5 commit 5401fb3

File tree

13 files changed

+67
-12
lines changed

13 files changed

+67
-12
lines changed

Tests/WebDriverAPI/AppSessionBase/AlarmClockBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public virtual void TestInit()
7272
{
7373
session.Navigate().Back();
7474
Thread.Sleep(TimeSpan.FromSeconds(1));
75+
session.DismissAlarmDialogIfThere();
7576

7677
try
7778
{
@@ -80,6 +81,7 @@ public virtual void TestInit()
8081
catch
8182
{
8283
session.FindElementByAccessibilityId("Back").Click(); // Press back button if navigating back somehow failed
84+
session.DismissAlarmDialogIfThere();
8385
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
8486
}
8587
}
@@ -145,6 +147,7 @@ protected static WindowsElement GetStaleElement()
145147
Thread.Sleep(TimeSpan.FromSeconds(0.5));
146148
WindowsElement staleElement = session.FindElementByAccessibilityId("AlarmSaveButton");
147149
session.Navigate().Back(); // Dismiss add alarm page
150+
session.DismissAlarmDialogIfThere();
148151
Thread.Sleep(TimeSpan.FromSeconds(2));
149152
return staleElement;
150153
}

Tests/WebDriverAPI/AppSessionBase/Utility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static void InitializeOrphanedSession()
113113
// Create new calculator session and close the window to get an orphaned element
114114
CleanupOrphanedSession();
115115
orphanedSession = CreateNewSession(CommonTestSettings.CalculatorAppId);
116-
orphanedElement = orphanedSession.FindElementByAccessibilityId("AppNameTitle");
116+
orphanedElement = orphanedSession.FindCalculatorTitleByAccessibilityId();
117117
orphanedWindowHandle = orphanedSession.CurrentWindowHandle;
118118
orphanedSession.Close();
119119
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//******************************************************************************
2+
//
3+
// Copyright (c) 2017 Microsoft Corporation. All rights reserved.
4+
//
5+
// This code is licensed under the MIT License (MIT).
6+
//
7+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13+
// THE SOFTWARE.
14+
//
15+
//******************************************************************************
16+
17+
using OpenQA.Selenium.Appium.Windows;
18+
using System;
19+
20+
namespace WebDriverAPI
21+
{
22+
static class WebDriverApiExtensions
23+
{
24+
internal static WindowsElement FindCalculatorTitleByAccessibilityId(this WindowsDriver<WindowsElement> session)
25+
{
26+
WindowsElement element;
27+
try
28+
{
29+
element = session.FindElementByAccessibilityId("AppNameTitle");
30+
}
31+
catch (InvalidOperationException)
32+
{
33+
element = session.FindElementByAccessibilityId("AppName");
34+
}
35+
return element;
36+
}
37+
38+
internal static void DismissAlarmDialogIfThere(this WindowsDriver<WindowsElement> session)
39+
{
40+
try
41+
{
42+
session.FindElementByAccessibilityId("SecondaryButton").Click();
43+
}
44+
catch (InvalidOperationException)
45+
{
46+
}
47+
}
48+
}
49+
}

Tests/WebDriverAPI/AppiumAppLaunch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void Launch_ModernApp()
6666
// This will create a new calculator window and point the current active session to it
6767
session.LaunchApp();
6868
Assert.AreEqual(originalSessionId, session.SessionId);
69-
Assert.AreEqual(originalTitle, session.Title);
69+
Assert.IsTrue(originalTitle.Contains(session.Title));
7070
Assert.AreEqual(originalWindowHandlesCount + 1, session.WindowHandles.Count);
7171
Assert.AreNotEqual(originalLaunchedWindowHandle, session.CurrentWindowHandle);
7272

Tests/WebDriverAPI/Back.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public void NavigateBack_ModernApp()
6666

6767
// Ensure alarms & clock are in Alarm Pivot view
6868
session.Navigate().Back();
69+
session.DismissAlarmDialogIfThere();
6970
session.FindElementByAccessibilityId("AlarmPivotItem").Click();
7071

7172
// Navigate to New Alarm view
@@ -74,6 +75,7 @@ public void NavigateBack_ModernApp()
7475

7576
// Navigate back to the original view
7677
session.Navigate().Back();
78+
session.DismissAlarmDialogIfThere();
7779
Assert.IsNotNull(session.FindElementByAccessibilityId("AlarmPivotItem"));
7880
}
7981

Tests/WebDriverAPI/ElementEquals.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void ClassCleanup()
4242
[TestMethod]
4343
public void CompareElements()
4444
{
45-
WindowsElement header = session.FindElementByAccessibilityId("AppNameTitle");
45+
WindowsElement header = session.FindCalculatorTitleByAccessibilityId();
4646
Assert.IsNotNull(header);
4747
Assert.IsFalse(header.Equals(referenceElement));
4848
Assert.IsFalse(referenceElement.Equals(header));

Tests/WebDriverAPI/ElementName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void ClassCleanup()
3838
[TestMethod]
3939
public void GetElementTagName()
4040
{
41-
WindowsElement header = session.FindElementByAccessibilityId("AppNameTitle");
41+
WindowsElement header = session.FindCalculatorTitleByAccessibilityId();
4242
Assert.AreEqual("ControlType.Text", header.TagName);
4343

4444
WindowsElement navButton = session.FindElementByAccessibilityId("NavButton");

Tests/WebDriverAPI/Mouse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void MouseClick()
7272
// Open a context menu on the application title bar to expose the context menu and verify that it contains minimize.
7373
// The context menu is parented on the desktop instead of the application. Thus, a desktop session is used to find it.
7474
// This command implicitly invoke /session/:sessionId/moveto and /session/:sessionId/click with button 2 parameter
75-
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppNameTitle");
75+
WindowsElement appNameTitle = session.FindCalculatorTitleByAccessibilityId();
7676
session.Mouse.ContextClick(appNameTitle.Coordinates);
7777
Thread.Sleep(TimeSpan.FromSeconds(1.5));
7878
WindowsDriver<WindowsElement> desktopSession = Utility.CreateNewSession(CommonTestSettings.DesktopAppId);
@@ -100,7 +100,7 @@ public void MouseDoubleClick()
100100
Assert.IsTrue(maximizeButton.Text.Contains("Maximize"));
101101

102102
// Perform mouse double click on the title bar to maximize the Calculator window
103-
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppNameTitle");
103+
WindowsElement appNameTitle = session.FindCalculatorTitleByAccessibilityId();
104104
session.Mouse.MouseMove(appNameTitle.Coordinates);
105105
session.Mouse.DoubleClick(null); // Pass null as this command omit the given parameter
106106
Thread.Sleep(TimeSpan.FromSeconds(1));
@@ -117,7 +117,7 @@ public void MouseDoubleClick()
117117
public void MouseDownMoveUp()
118118
{
119119
const int offset = 100;
120-
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppNameTitle");
120+
WindowsElement appNameTitle = session.FindCalculatorTitleByAccessibilityId();
121121
Assert.IsNotNull(appNameTitle);
122122

123123
// Save application window original position

Tests/WebDriverAPI/Session.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void CreateSession_ModernApp()
8787
session = new WindowsDriver<WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
8888
Assert.IsNotNull(session);
8989
Assert.IsNotNull(session.SessionId);
90-
Assert.AreEqual("Calculator", session.Title);
90+
Assert.IsTrue(session.Title.Contains("Calculator"));
9191
}
9292

9393
[TestMethod]
@@ -229,7 +229,7 @@ public void CreateSessionFromExistingWindowHandle_ModernApp()
229229

230230
// Verify that newly created session is indeed attached to the correct application top level window
231231
Assert.AreEqual(secondarySession.CurrentWindowHandle, session.CurrentWindowHandle);
232-
Assert.AreEqual(secondarySession.FindElementByAccessibilityId("AppNameTitle"), session.FindElementByAccessibilityId("AppNameTitle"));
232+
Assert.AreEqual(secondarySession.FindCalculatorTitleByAccessibilityId(), session.FindCalculatorTitleByAccessibilityId());
233233
}
234234

235235
[TestMethod]

Tests/WebDriverAPI/Title.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void GetTitle_ModernApp()
5656
{
5757
session = Utility.CreateNewSession(CommonTestSettings.CalculatorAppId);
5858
Assert.IsNotNull(session);
59-
Assert.AreEqual("Calculator", session.Title);
59+
Assert.IsTrue(session.Title.Contains("Calculator"));
6060
}
6161

6262
[TestMethod]

0 commit comments

Comments
 (0)