Skip to content

Commit 5dbf74d

Browse files
committed
Merged PR 2991474: Update all C# samples to work with the latest Windows 10 in-box apps and more recent NuGet Packages
Update AlarmClockTest, CalculatorTest, and CortanaTest samples to align with the latest application update Improve NotepadTest reliability by using a different search query Update sample README.md documents with better instructions and running requirements Related work items: #20771705
2 parents e99e77f + 78b3fbb commit 5dbf74d

22 files changed

+148
-141
lines changed

Samples/C#/AlarmClockTest/AlarmClockSession.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void Setup(TestContext context)
4545
Assert.IsNotNull(session.SessionId);
4646

4747
// Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
48-
session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5));
48+
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
4949

5050
// Initialize touch screen object
5151
touchScreen = new RemoteTouchScreen(session);
@@ -69,24 +69,24 @@ public static void TearDown()
6969
[TestInitialize]
7070
public virtual void TestInit()
7171
{
72-
WindowsElement alarmTabElement = null;
72+
WindowsElement alarmButtonElement = null;
7373

7474
// Attempt to go back to the main page in case Alarms & Clock app is started in EditAlarm view
7575
try
7676
{
77-
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
77+
alarmButtonElement = session.FindElementByAccessibilityId("AlarmButton");
7878
}
7979
catch
8080
{
81-
// Click back button if application is in a nested page such as New Alarm or New Timer
82-
session.FindElementByAccessibilityId("Back").Click();
81+
// Click cancel button if application is in a nested page such as New Alarm or New Timer
82+
session.FindElementByAccessibilityId("CancelButton").Click();
8383
Thread.Sleep(TimeSpan.FromSeconds(1));
84-
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
84+
alarmButtonElement = session.FindElementByAccessibilityId("AlarmButton");
8585
}
8686

87-
// Verify that the app is in the main view showing alarmTabElement
88-
Assert.IsNotNull(alarmTabElement);
89-
Assert.IsTrue(alarmTabElement.Displayed);
87+
// Verify that the app is in the main view showing alarmButtonElement
88+
Assert.IsNotNull(alarmButtonElement);
89+
Assert.IsTrue(alarmButtonElement.Displayed);
9090
}
9191
}
9292
}

Samples/C#/AlarmClockTest/AlarmClockTest.csproj

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,22 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="appium-dotnet-driver, Version=3.0.0.1, Culture=neutral, processorArchitecture=MSIL">
39-
<HintPath>packages\Appium.WebDriver.3.0.0.1\lib\net45\appium-dotnet-driver.dll</HintPath>
40-
<Private>True</Private>
38+
<Reference Include="appium-dotnet-driver, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
39+
<HintPath>packages\Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview\lib\net45\appium-dotnet-driver.dll</HintPath>
4140
</Reference>
42-
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
43-
<HintPath>packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
44-
<Private>True</Private>
41+
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
42+
<HintPath>packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
4543
</Reference>
46-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
47-
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
48-
<Private>True</Private>
44+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
45+
<HintPath>packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
4946
</Reference>
5047
<Reference Include="System" />
5148
<Reference Include="System.Drawing" />
52-
<Reference Include="WebDriver, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
53-
<HintPath>packages\Selenium.WebDriver.3.0.1\lib\net40\WebDriver.dll</HintPath>
54-
<Private>True</Private>
49+
<Reference Include="WebDriver, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
50+
<HintPath>packages\Selenium.WebDriver.3.8.0\lib\net45\WebDriver.dll</HintPath>
5551
</Reference>
56-
<Reference Include="WebDriver.Support, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
57-
<HintPath>packages\Selenium.Support.3.0.1\lib\net40\WebDriver.Support.dll</HintPath>
58-
<Private>True</Private>
52+
<Reference Include="WebDriver.Support, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
53+
<HintPath>packages\Selenium.Support.3.8.0\lib\net45\WebDriver.Support.dll</HintPath>
5954
</Reference>
6055
</ItemGroup>
6156
<Choose>

Samples/C#/AlarmClockTest/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ AlarmClockTest is a sample test project that runs and validates basic UI scenari
44

55
This test project highlights some common interactions below that can be put together to perform and verify various UI scenario on a modern app.
66
- Creating a modern UWP app session
7-
- Navigating between tabs (pivot items)
7+
- Navigating between tabs/pages
88
- Sending click action to an element
99
- Sending keyboard input to a text box
1010
- Sending touch action
@@ -18,19 +18,20 @@ This test project highlights some common interactions below that can be put toge
1818

1919
## Requirements
2020

21-
- Windows 10 PC with the latest Windows 10 version (Version 1607 or later)
22-
- Microsoft Visual Studio 2015 or later
21+
- Windows 10 PC with the latest Windows 10 version (Version 1809 or later)
22+
- Microsoft Visual Studio 2017 or later
2323

2424

2525
## Getting Started
2626

27-
1. Open `AlarmClockTest.sln` in Visual Studio
28-
2. Select **Test** > **Windows** > **Test Explorer**
29-
3. Select **Run All** on the test pane or through menu **Test** > **Run** > **All Tests**
27+
1. [Run](../../../README.md#installing-and-running-windows-application-driver) `WinAppDriver.exe` on the test device
28+
2. Open `AlarmClockTest.sln` in Visual Studio
29+
3. Select **Build** > **Rebuild Solution**
30+
4. Select **Test** > **Windows** > **Test Explorer**
31+
5. Select **Run All** on the test pane or through menu **Test** > **Run** > **All Tests**
3032

3133
> Once the project is successfully built, you can use the **TestExplorer** to pick and choose the test scenario(s) to run
3234
33-
3435
## Adding/Updating Test Scenario
3536

3637
Please follow the guidelines below to maintain test reliability and conciseness:

Samples/C#/AlarmClockTest/ScenarioAlarm.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ScenarioAlarm : AlarmClockSession
3030
public void AlarmAdd()
3131
{
3232
// Navigate to New Alarm page
33+
Thread.Sleep(TimeSpan.FromSeconds(1));
3334
session.FindElementByAccessibilityId("AddAlarmButton").Click();
3435

3536
// Set alarm name
@@ -119,7 +120,7 @@ public override void TestInit()
119120
base.TestInit();
120121

121122
// Navigate to Alarm tab
122-
session.FindElementByAccessibilityId("AlarmPivotItem").Click();
123+
session.FindElementByAccessibilityId("AlarmButton").Click();
123124
}
124125
}
125126
}

Samples/C#/AlarmClockTest/ScenarioStopwatch.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ public class ScenarioStopwatch : AlarmClockSession
2929
[TestMethod]
3030
public void StopwatchLap()
3131
{
32-
int numberOfEntry = 3;
33-
var stopwatchPivotItem = session.FindElementByAccessibilityId("StopwatchPivotItem");
32+
int numberOfEntry = 8;
3433

3534
// Start the stopwatch
36-
var stopwatchPlayPauseButton = stopwatchPivotItem.FindElementByAccessibilityId("StopwatchPlayPauseButton");
35+
var stopwatchPlayPauseButton = session.FindElementByAccessibilityId("StopwatchPlayPauseButton");
3736
stopwatchPlayPauseButton.Click();
3837

3938
// Create lap entries
40-
var stopwatchLapButton = stopwatchPivotItem.FindElementByAccessibilityId("StopWatchLapButton");
39+
var stopwatchLapButton = session.FindElementByAccessibilityId("StopWatchLapButton");
4140
for (uint count = 0; count < numberOfEntry; count++)
4241
{
4342
stopwatchLapButton.Click();
@@ -48,7 +47,7 @@ public void StopwatchLap()
4847
Thread.Sleep(TimeSpan.FromSeconds(0.5));
4948

5049
// Verify that the lap entries are created
51-
var lapListView = stopwatchPivotItem.FindElementByAccessibilityId("LapsAndSplitsListView");
50+
var lapListView = session.FindElementByAccessibilityId("LapsAndSplitsListView");
5251
var lapEntries = lapListView.FindElementsByClassName("ListViewItem");
5352
Assert.IsNotNull(lapEntries);
5453
Assert.AreEqual(numberOfEntry, lapEntries.Count);
@@ -60,13 +59,13 @@ public void StopwatchLap()
6059
Assert.IsFalse(firstLapEntry.Displayed);
6160

6261
// Horizontally scroll the list up and verify that the fist lap entry is now displayed while the last entry is now hidden
63-
touchScreen.Scroll(lapListView.Coordinates, 0, -50);
62+
touchScreen.Scroll(lapListView.Coordinates, 0, -100);
6463
Thread.Sleep(TimeSpan.FromSeconds(1));
6564
Assert.IsTrue(firstLapEntry.Displayed);
6665
Assert.IsFalse(lastLapEntry.Displayed);
6766

6867
// Horizontally scroll the list down and verify that the last lap entry is now displayed while the first entry is now hidden again
69-
touchScreen.Scroll(lapListView.Coordinates, 0, 50);
68+
touchScreen.Scroll(lapListView.Coordinates, 0, 100);
7069
Thread.Sleep(TimeSpan.FromSeconds(1));
7170
Assert.IsTrue(lastLapEntry.Displayed);
7271
Assert.IsFalse(firstLapEntry.Displayed);
@@ -75,15 +74,14 @@ public void StopwatchLap()
7574
[TestMethod]
7675
public void StopwatchStart()
7776
{
78-
var stopwatchPivotItem = session.FindElementByAccessibilityId("StopwatchPivotItem");
79-
var stopwatchResetButton = stopwatchPivotItem.FindElementByAccessibilityId("StopWatchResetButton");
77+
var stopwatchResetButton = session.FindElementByAccessibilityId("StopWatchResetButton");
8078

8179
// Track the reset stopwatch timer text for comparison
82-
var stopwatchTimer = stopwatchPivotItem.FindElementByAccessibilityId("StopwatchTimerText");
80+
var stopwatchTimer = session.FindElementByAccessibilityId("StopwatchTimerText");
8381
string stopwatchTimerText = stopwatchTimer.GetAttribute("Name");
8482

8583
// Verify that the stopwatchPlayPauseButton button says Start and the stopwatchResetButton is disabled
86-
var stopwatchPlayPauseButton = stopwatchPivotItem.FindElementByAccessibilityId("StopwatchPlayPauseButton");
84+
var stopwatchPlayPauseButton = session.FindElementByAccessibilityId("StopwatchPlayPauseButton");
8785
Assert.AreEqual("Start", stopwatchPlayPauseButton.Text);
8886
Assert.IsFalse(stopwatchResetButton.Enabled);
8987

@@ -103,7 +101,6 @@ public void StopwatchStart()
103101
Assert.AreNotEqual(stopwatchTimerText, stopwatchTimer.GetAttribute("Name"));
104102
}
105103

106-
107104
[ClassInitialize]
108105
public static void ClassInitialize(TestContext context)
109106
{
@@ -112,7 +109,7 @@ public static void ClassInitialize(TestContext context)
112109
// Save application window original size and temporarily set it to 500 x 500
113110
originalSize = session.Manage().Window.Size;
114111
Assert.IsNotNull(originalSize);
115-
session.Manage().Window.Size = new Size(500, 500);
112+
session.Manage().Window.Size = new Size(550, 500);
116113
}
117114

118115
[ClassCleanup]
@@ -131,7 +128,7 @@ public override void TestInit()
131128
base.TestInit();
132129

133130
// Navigate to Stopwatch tab
134-
session.FindElementByAccessibilityId("StopwatchPivotItem").Click();
131+
session.FindElementByAccessibilityId("StopwatchButton").Click();
135132

136133
// Stop the stopwatch if it is running and reset it
137134
TestCleanup();
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Appium.WebDriver" version="3.0.0.1" targetFramework="net45" />
4-
<package id="Castle.Core" version="3.3.3" targetFramework="net45" />
5-
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
6-
<package id="Selenium.Support" version="3.0.1" targetFramework="net45" />
7-
<package id="Selenium.WebDriver" version="3.0.1" targetFramework="net45" />
3+
<package id="Castle.Core" version="4.2.1" targetFramework="net45" />
4+
<package id="Microsoft.WinAppDriver.Appium.WebDriver" version="1.0.1-Preview" targetFramework="net45" />
5+
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
6+
<package id="Selenium.Support" version="3.8.0" targetFramework="net45" />
7+
<package id="Selenium.WebDriver" version="3.8.0" targetFramework="net45" />
88
</packages>

Samples/C#/CalculatorTest/CalculatorSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void Setup(TestContext context)
4343
Assert.IsNotNull(session);
4444

4545
// Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
46-
session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5));
46+
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
4747
}
4848
}
4949

Samples/C#/CalculatorTest/CalculatorTest.csproj

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,29 @@
3838
<WarningLevel>4</WarningLevel>
3939
</PropertyGroup>
4040
<ItemGroup>
41-
<Reference Include="appium-dotnet-driver, Version=3.0.0.1, Culture=neutral, processorArchitecture=MSIL">
42-
<HintPath>packages\Appium.WebDriver.3.0.0.1\lib\net45\appium-dotnet-driver.dll</HintPath>
43-
<Private>True</Private>
41+
<Reference Include="appium-dotnet-driver, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
42+
<HintPath>packages\Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview\lib\net45\appium-dotnet-driver.dll</HintPath>
4443
</Reference>
4544
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
46-
<HintPath>packages\Castle.Core.4.0.0\lib\net45\Castle.Core.dll</HintPath>
47-
<Private>True</Private>
45+
<HintPath>packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
4846
</Reference>
4947
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5048
<HintPath>packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
51-
<Private>True</Private>
5249
</Reference>
5350
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5451
<HintPath>packages\MSTest.TestFramework.1.2.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
55-
<Private>True</Private>
5652
</Reference>
57-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
58-
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
59-
<Private>True</Private>
53+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
54+
<HintPath>packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
6055
</Reference>
6156
<Reference Include="System" />
57+
<Reference Include="System.Configuration" />
6258
<Reference Include="System.Drawing" />
63-
<Reference Include="WebDriver, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
64-
<HintPath>packages\Selenium.WebDriver.3.0.1\lib\net40\WebDriver.dll</HintPath>
65-
<Private>True</Private>
59+
<Reference Include="WebDriver, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
60+
<HintPath>packages\Selenium.WebDriver.3.8.0\lib\net45\WebDriver.dll</HintPath>
6661
</Reference>
67-
<Reference Include="WebDriver.Support, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
68-
<HintPath>packages\Selenium.Support.3.0.1\lib\net40\WebDriver.Support.dll</HintPath>
69-
<Private>True</Private>
62+
<Reference Include="WebDriver.Support, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
63+
<HintPath>packages\Selenium.Support.3.8.0\lib\net45\WebDriver.Support.dll</HintPath>
7064
</Reference>
7165
</ItemGroup>
7266
<Choose>

Samples/C#/CalculatorTest/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ This test project highlights the following basic interactions to demonstrate how
1414

1515
## Requirements
1616

17-
- Windows 10 PC with the latest Windows 10 version (Version 1607 or later)
18-
- Microsoft Visual Studio 2015 or later
17+
- Windows 10 PC with the latest Windows 10 version (Version 1809 or later)
18+
- Microsoft Visual Studio 2017 or later
1919

2020

2121
## Getting Started
2222

23-
1. Open `CalculatorTest.sln` in Visual Studio
24-
2. Select **Test** > **Windows** > **Test Explorer**
25-
3. Select **Run All** on the test pane or through menu **Test** > **Run** > **All Tests**
23+
1. [Run](../../../README.md#installing-and-running-windows-application-driver) `WinAppDriver.exe` on the test device
24+
2. Open `CalculatorTest.sln` in Visual Studio
25+
3. Select **Build** > **Rebuild Solution**
26+
4. Select **Test** > **Windows** > **Test Explorer**
27+
5. Select **Run All** on the test pane or through menu **Test** > **Run** > **All Tests**
2628

2729
> Once the project is successfully built, you can use the **TestExplorer** to pick and choose the test scenario(s) to run
2830
31+
> If Visual Studio fail to discover and run the test scenarios:
32+
> 1. Select **Tools** > **Options...** > **Test**
33+
> 2. Under *Active Solution*, uncheck *For improved performance, only use test adapters in test assembly folder or as specified in runsettings file*
2934
3035
## Adding/Updating Test Scenario
3136

Samples/C#/CalculatorTest/ScenarioStandard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static void ClassInitialize(TestContext context)
106106
// Ensure that calculator is in standard mode
107107
if (!header.Text.Equals("Standard", StringComparison.OrdinalIgnoreCase))
108108
{
109-
session.FindElementByAccessibilityId("NavButton").Click();
109+
session.FindElementByAccessibilityId("TogglePaneButton").Click();
110110
Thread.Sleep(TimeSpan.FromSeconds(1));
111111
var splitViewPane = session.FindElementByClassName("SplitViewPane");
112112
splitViewPane.FindElementByName("Standard Calculator").Click();

0 commit comments

Comments
 (0)