Skip to content

Commit 26b5471

Browse files
committed
Merged PR 649336: Rename and reorganized test methods to generate clearer test results
Rename test methods to generate better organized test results Add missing tests for XPath expression error scenarios Add missing tests for element not visible action error scenarios Optimize AlarmClockBase by avoiding click action on test initialize Update error scenarios to check for exception types and error messages Add scenarios for finding element/elements using element Ids Add missing error scenarios for Source, Timeouts, Keys, and Windows tests Refactor ElementSendKeys test to use Alarms application instead of Notepad Related work items: #9226701
2 parents 18c5348 + 9862eb9 commit 26b5471

40 files changed

+1394
-1038
lines changed

Tests/W3CWebDriver/AppSessionBase/AlarmClockBase.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//
1515
//******************************************************************************
1616

17-
using System;
1817
using Microsoft.VisualStudio.TestTools.UnitTesting;
1918
using OpenQA.Selenium.Appium.Windows;
2019
using OpenQA.Selenium.Remote;
@@ -57,7 +56,7 @@ public static void TearDown()
5756
}
5857

5958
[TestInitialize]
60-
public void TestInit()
59+
public virtual void TestInit()
6160
{
6261
// Attempt to go back to the main page in case Alarm & Clock app is started in EditAlarm view
6362
try
@@ -71,7 +70,10 @@ public void TestInit()
7170
}
7271

7372
Assert.IsNotNull(alarmTabElement);
74-
alarmTabElement.Click();
73+
if (!alarmTabElement.Selected)
74+
{
75+
alarmTabElement.Click();
76+
}
7577
}
7678

7779
protected void AddAlarmEntry(string alarmName)
@@ -88,7 +90,7 @@ protected void DeletePreviouslyCreatedAlarmEntry(string alarmName)
8890
{
8991
try
9092
{
91-
var alarmEntry = session.FindElementByXPath(string.Format("//ListItem[starts-with(@Name, \"{0}\")]", alarmName));
93+
var alarmEntry = session.FindElementByXPath($"//ListItem[starts-with(@Name, \"{alarmName}\")]");
9294
session.Mouse.ContextClick(alarmEntry.Coordinates);
9395
session.FindElementByName("Delete").Click();
9496
}
@@ -126,7 +128,7 @@ protected static WindowsElement GetStaleElement()
126128
session.FindElementByAccessibilityId("AddAlarmButton").Click();
127129
WindowsElement staleElement = session.FindElementByAccessibilityId("CancelButton");
128130
staleElement.Click();
129-
System.Threading.Thread.Sleep(1000);
131+
System.Threading.Thread.Sleep(System.TimeSpan.FromSeconds(1));
130132
return staleElement;
131133
}
132134
}

Tests/W3CWebDriver/AppSessionBase/CalculatorBase.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using Microsoft.VisualStudio.TestTools.UnitTesting;
1818
using OpenQA.Selenium.Appium.Windows;
1919
using OpenQA.Selenium.Remote;
20+
using System;
21+
using System.Threading;
2022

2123
namespace W3CWebDriver
2224
{
@@ -49,10 +51,10 @@ public static void Setup(TestContext context)
4951
if (!header.Text.Equals("Standard"))
5052
{
5153
session.FindElementByAccessibilityId("NavButton").Click();
52-
System.Threading.Thread.Sleep(1000);
54+
Thread.Sleep(TimeSpan.FromSeconds(1));
5355
var splitViewPane = session.FindElementByClassName("SplitViewPane");
5456
splitViewPane.FindElementByName("Standard Calculator").Click();
55-
System.Threading.Thread.Sleep(1000);
57+
Thread.Sleep(TimeSpan.FromSeconds(1));
5658
Assert.AreEqual("Standard", header.Text);
5759
}
5860
}
@@ -89,11 +91,11 @@ protected static WindowsElement GetStaleElement()
8991
session.FindElementByAccessibilityId("MemoryButton").Click();
9092
}
9193

92-
System.Threading.Thread.Sleep(1000);
94+
Thread.Sleep(TimeSpan.FromSeconds(1));
9395
WindowsElement staleElement = session.FindElementByAccessibilityId("MemoryListView").FindElementByName("0") as WindowsElement;
9496
session.FindElementByAccessibilityId("ClearMemory").Click();
9597
header.Click(); // Dismiss memory flyout that could be displayed if calculator is in compact mode
96-
System.Threading.Thread.Sleep(1000);
98+
Thread.Sleep(TimeSpan.FromSeconds(1));
9799
return staleElement;
98100
}
99101
}

Tests/W3CWebDriver/AppSessionBase/CommonTestSettings.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class CommonTestSettings
3030
public const string EdgeAboutFlagsURL = "about:flags";
3131
public const string EdgeAboutTabsURL = "about:tabs";
3232

33-
public const string TestFileName = "TestFile.txt";
34-
public const string TestFolderLocation = "%TEMP%";
33+
public const string TestFileName = @"TestFile.txt";
34+
public const string TestFolderLocation = @"%TEMP%";
3535
}
3636

3737
public class ErrorStrings
@@ -40,5 +40,8 @@ public class ErrorStrings
4040
public const string NoSuchElement = "An element could not be located on the page using the given search parameters.";
4141
public const string NoSuchWindow = "Currently selected window has been closed";
4242
public const string StaleElementReference = "An element command failed because the referenced element is no longer attached to the DOM.";
43+
public const string UnimplementedCommandLocator = "Unexpected error. Unimplemented Command: {0} locator strategy is not supported";
44+
public const string UnimplementedCommandTimeoutType = "Unexpected error. Unimplemented Command: {0} timeout type is not supported";
45+
public const string XPathLookupError = "Invalid XPath expression: {0} (XPathLookupError)";
4346
}
4447
}

Tests/W3CWebDriver/AppSessionBase/EdgeBase.cs

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
//
1515
//******************************************************************************
1616

17-
using System;
18-
using System.Collections.Generic;
19-
using System.IO;
20-
using System.Net;
21-
using System.Text;
2217
using Microsoft.VisualStudio.TestTools.UnitTesting;
23-
using Newtonsoft.Json.Linq;
2418
using OpenQA.Selenium.Appium.Windows;
2519
using OpenQA.Selenium.Remote;
20+
using System;
21+
using System.Threading;
2622

2723
namespace W3CWebDriver
2824
{
@@ -53,7 +49,7 @@ public static void Setup(TestContext context)
5349
}
5450

5551
// Track the Microsoft Edge starting page title to be used to initialize all test cases
56-
System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
52+
Thread.Sleep(TimeSpan.FromSeconds(1));
5753
startingPageTitle = session.Title;
5854

5955
// Handle Microsoft Edge restored state by starting fresh
@@ -62,7 +58,7 @@ public static void Setup(TestContext context)
6258
try
6359
{
6460
session.FindElementByXPath("//Button[@Name='Start fresh']").Click();
65-
System.Threading.Thread.Sleep(3000); // Sleep for 3 seconds
61+
Thread.Sleep(TimeSpan.FromSeconds(3));
6662
startingPageTitle = session.Title;
6763
}
6864
catch { }
@@ -109,20 +105,20 @@ protected static RemoteWebElement GetStaleElement()
109105
RemoteWebElement staleElement = null;
110106

111107
session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.EdgeAboutTabsURL + OpenQA.Selenium.Keys.Enter);
112-
System.Threading.Thread.Sleep(2000); // Sleep for 2 seconds
108+
Thread.Sleep(TimeSpan.FromSeconds(2));
113109
var originalTitle = session.Title;
114110
Assert.AreNotEqual(string.Empty, originalTitle);
115111

116112
// Navigate to Edge about:flags page
117113
session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.EdgeAboutFlagsURL + OpenQA.Selenium.Keys.Enter);
118-
System.Threading.Thread.Sleep(2000); // Sleep for 2 seconds
114+
Thread.Sleep(TimeSpan.FromSeconds(2));
119115
Assert.AreNotEqual(originalTitle, session.Title);
120116

121117
// Save a reference to Reset all flags button on the page and navigate back to home
122118
staleElement = session.FindElementByAccessibilityId("ResetAllFlags");
123119
Assert.IsNotNull(staleElement);
124120
session.Navigate().Back();
125-
System.Threading.Thread.Sleep(1000);
121+
Thread.Sleep(TimeSpan.FromSeconds(1));
126122
Assert.AreEqual(originalTitle, session.Title);
127123

128124
return staleElement;

Tests/W3CWebDriver/Back.cs

+17-20
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
//
1515
//******************************************************************************
1616

17-
using System;
1817
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using OpenQA.Selenium;
1919
using OpenQA.Selenium.Appium.Windows;
20-
using OpenQA.Selenium.Remote;
20+
using System;
21+
using System.Threading;
2122

2223
namespace W3CWebDriver
2324
{
@@ -27,32 +28,32 @@ public class Back
2728
private WindowsDriver<WindowsElement> session = null;
2829

2930
[TestMethod]
30-
public void NavigateBackBrowser()
31+
public void NavigateBack_Browser()
3132
{
3233
session = Utility.CreateNewSession(CommonTestSettings.EdgeAppId);
3334
Assert.IsNotNull(session);
3435

35-
session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.EdgeAboutFlagsURL + OpenQA.Selenium.Keys.Enter);
36-
System.Threading.Thread.Sleep(1000); // Sleep for 1 second
36+
session.FindElementByAccessibilityId("addressEditBox").SendKeys(CommonTestSettings.EdgeAboutFlagsURL + Keys.Enter);
37+
Thread.Sleep(TimeSpan.FromSeconds(1));
3738
var originalTitle = session.Title;
38-
Assert.AreNotEqual(String.Empty, originalTitle);
39+
Assert.AreNotEqual(string.Empty, originalTitle);
3940

4041
// Navigate to different URLs
4142
var addressEditBox = session.FindElementByAccessibilityId("addressEditBox");
42-
addressEditBox.SendKeys(CommonTestSettings.EdgeAboutBlankURL + OpenQA.Selenium.Keys.Enter);
43+
addressEditBox.SendKeys(CommonTestSettings.EdgeAboutBlankURL + Keys.Enter);
4344
Assert.AreNotEqual(originalTitle, session.Title);
4445

4546
// Navigate back to original URL
4647
session.Navigate().Back();
47-
System.Threading.Thread.Sleep(1000); // Sleep for 1 second
48+
Thread.Sleep(TimeSpan.FromSeconds(1));
4849
Assert.AreEqual(originalTitle, session.Title);
4950

5051
session.Quit();
5152
session = null;
5253
}
5354

5455
[TestMethod]
55-
public void NavigateBackModernApp()
56+
public void NavigateBack_ModernApp()
5657
{
5758
session = Utility.CreateNewSession(CommonTestSettings.AlarmClockAppId);
5859
Assert.IsNotNull(session);
@@ -71,22 +72,18 @@ public void NavigateBackModernApp()
7172
}
7273

7374
[TestMethod]
74-
public void NavigateBackSystemApp()
75+
public void NavigateBack_SystemApp()
7576
{
7677
session = Utility.CreateNewSession(CommonTestSettings.ExplorerAppId);
7778
Assert.IsNotNull(session);
7879

79-
System.Threading.Thread.Sleep(1000); // Sleep for 1 second
80+
Thread.Sleep(TimeSpan.FromSeconds(1));
8081
var originalTitle = session.Title;
81-
Assert.AreNotEqual(String.Empty, originalTitle);
82+
Assert.AreNotEqual(string.Empty, originalTitle);
8283

8384
// Navigate Windows Explorer to change folder
84-
var targetLocation = @"%TEMP%\";
85-
var addressBandRoot = session.FindElementByClassName("Address Band Root");
86-
var addressToolbar = addressBandRoot.FindElementByAccessibilityId("1001"); // Address Band Toolbar
87-
session.Mouse.Click(addressToolbar.Coordinates);
88-
addressBandRoot.FindElementByAccessibilityId("41477").SendKeys(targetLocation + OpenQA.Selenium.Keys.Enter);
89-
System.Threading.Thread.Sleep(1000); // Sleep for 1 second
85+
session.Keyboard.SendKeys(Keys.Alt + "d" + Keys.Alt + CommonTestSettings.TestFolderLocation + Keys.Enter);
86+
Thread.Sleep(TimeSpan.FromSeconds(1));
9087
Assert.AreNotEqual(originalTitle, session.Title);
9188

9289
// Navigate back to the original folder
@@ -98,14 +95,14 @@ public void NavigateBackSystemApp()
9895
}
9996

10097
[TestMethod]
101-
public void ErrorNavigateBackNoSuchWindow()
98+
public void NavigateBackError_NoSuchWindow()
10299
{
103100
try
104101
{
105102
Utility.GetOrphanedSession().Navigate().Back();
106103
Assert.Fail("Exception should have been thrown");
107104
}
108-
catch (System.InvalidOperationException exception)
105+
catch (InvalidOperationException exception)
109106
{
110107
Assert.AreEqual(ErrorStrings.NoSuchWindow, exception.Message);
111108
}

0 commit comments

Comments
 (0)