Skip to content

Commit 22a8601

Browse files
committed
Create a new Paint sample test project highlighting multi-touch feature and performance
1 parent 668c852 commit 22a8601

File tree

7 files changed

+534
-0
lines changed

7 files changed

+534
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//******************************************************************************
2+
//
3+
// Copyright (c) 2018 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 Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using OpenQA.Selenium;
19+
using OpenQA.Selenium.Appium.Windows;
20+
using OpenQA.Selenium.Remote;
21+
using System;
22+
23+
namespace PaintTest
24+
{
25+
public class PaintSession
26+
{
27+
// Note: append /wd/hub to the URL if you're directing the test at Appium
28+
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
29+
private const string PaintAppId = @"C:\Windows\System32\mspaint.exe";
30+
31+
protected static WindowsDriver<WindowsElement> session;
32+
33+
public static void Setup(TestContext context)
34+
{
35+
// Launch Paint 3D application if it is not yet launched
36+
if (session == null)
37+
{
38+
// Create a new session to launch Paint 3D application
39+
DesiredCapabilities appCapabilities = new DesiredCapabilities();
40+
appCapabilities.SetCapability("app", PaintAppId);
41+
appCapabilities.SetCapability("deviceName", "WindowsPC");
42+
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
43+
Assert.IsNotNull(session);
44+
45+
// 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().ImplicitWait = TimeSpan.FromSeconds(1.5);
47+
}
48+
}
49+
50+
public static void TearDown()
51+
{
52+
// Close the application and delete the session
53+
if (session != null)
54+
{
55+
ClosePaint();
56+
session.Quit();
57+
session = null;
58+
}
59+
}
60+
61+
[TestInitialize]
62+
public void CreateNewPaintProject()
63+
{
64+
// Create a new Paint 3D project by pressing Ctrl + N
65+
session.SwitchTo().Window(session.CurrentWindowHandle);
66+
session.Keyboard.SendKeys(Keys.Control + "n" + Keys.Control);
67+
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
68+
DismissSaveConfirmDialog();
69+
}
70+
71+
private static void DismissSaveConfirmDialog()
72+
{
73+
try
74+
{
75+
session.FindElementByName("Don't Save").Click();
76+
}
77+
catch { }
78+
}
79+
80+
private static void ClosePaint()
81+
{
82+
try
83+
{
84+
session.Close();
85+
string currentHandle = session.CurrentWindowHandle; // This should throw if the window is closed successfully
86+
87+
// When the Paint 3D window remains open because of save confirmation dialog, attempt to close modal dialog
88+
DismissSaveConfirmDialog();
89+
}
90+
catch { }
91+
}
92+
}
93+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{75FD12B5-F371-4C03-8F60-439144865AF8}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>PaintTest</RootNamespace>
11+
<AssemblyName>PaintTest</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
16+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
17+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
18+
<IsCodedUITest>False</IsCodedUITest>
19+
<TestProjectType>UnitTest</TestProjectType>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
24+
<DebugSymbols>true</DebugSymbols>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
27+
<OutputPath>bin\Debug\</OutputPath>
28+
<DefineConstants>DEBUG;TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
33+
<DebugType>pdbonly</DebugType>
34+
<Optimize>true</Optimize>
35+
<OutputPath>bin\Release\</OutputPath>
36+
<DefineConstants>TRACE</DefineConstants>
37+
<ErrorReport>prompt</ErrorReport>
38+
<WarningLevel>4</WarningLevel>
39+
</PropertyGroup>
40+
<ItemGroup>
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>
43+
</Reference>
44+
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
45+
<HintPath>packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
48+
<HintPath>packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51+
<HintPath>packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
52+
</Reference>
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>
55+
</Reference>
56+
<Reference Include="System" />
57+
<Reference Include="System.Configuration" />
58+
<Reference Include="System.Core" />
59+
<Reference Include="System.Drawing" />
60+
<Reference Include="WebDriver, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
61+
<HintPath>packages\Selenium.WebDriver.3.8.0\lib\net45\WebDriver.dll</HintPath>
62+
</Reference>
63+
<Reference Include="WebDriver.Support, Version=3.8.0.0, Culture=neutral, processorArchitecture=MSIL">
64+
<HintPath>packages\Selenium.Support.3.8.0\lib\net45\WebDriver.Support.dll</HintPath>
65+
</Reference>
66+
</ItemGroup>
67+
<ItemGroup>
68+
<Compile Include="PaintSession.cs" />
69+
<Compile Include="Properties\AssemblyInfo.cs" />
70+
<Compile Include="ScenarioDraw.cs" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<None Include="packages.config" />
74+
</ItemGroup>
75+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
76+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
78+
<PropertyGroup>
79+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
80+
</PropertyGroup>
81+
<Error Condition="!Exists('packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" />
82+
<Error Condition="!Exists('packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" />
83+
</Target>
84+
<Import Project="packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" />
85+
</Project>

Samples/C#/PaintTest/PaintTest.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2035
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaintTest", "PaintTest.csproj", "{75FD12B5-F371-4C03-8F60-439144865AF8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{75FD12B5-F371-4C03-8F60-439144865AF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{75FD12B5-F371-4C03-8F60-439144865AF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{75FD12B5-F371-4C03-8F60-439144865AF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{75FD12B5-F371-4C03-8F60-439144865AF8}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {AF04FDF9-06D1-4320-BCE5-1DEED1DAF27F}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle("PaintTest")]
6+
[assembly: AssemblyDescription("")]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany("")]
9+
[assembly: AssemblyProduct("PaintTest")]
10+
[assembly: AssemblyCopyright("Copyright © 2018")]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: Guid("75fd12b5-f371-4c03-8f60-439144865af8")]
17+
18+
// [assembly: AssemblyVersion("1.0.*")]
19+
[assembly: AssemblyVersion("1.0.0.0")]
20+
[assembly: AssemblyFileVersion("1.0.0.0")]

Samples/C#/PaintTest/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# PaintTest
2+
3+
PaintTest is a sample test project that highlights the capabilities of multi-touch interactions through the actions API using the Windows 10 built-in **Paint** application.
4+
5+
This test project highlights some Actions API features below.
6+
- Drawing with up to 10 touch points simultaneously
7+
- Smooth and precise interpolation
8+
- Responsive interactions of many input points
9+
10+
11+
## Requirements
12+
13+
- Windows 10 PC with the latest Windows 10 version (Version 1607 or later)
14+
- Microsoft Visual Studio 2017 or later
15+
16+
17+
## Getting Started
18+
19+
1. [Run](../../../README.md#installing-and-running-windows-application-driver) `WinAppDriver.exe` on the test device
20+
1. Open `PaintTest.sln` in Visual Studio
21+
2. Select **Test** > **Windows** > **Test Explorer**
22+
3. Select **Run All** on the test pane or through menu **Test** > **Run** > **All Tests**
23+
24+
> Once the project is successfully built, you can use the **TestExplorer** to pick and choose the test scenario(s) to run
25+
26+
27+
## Including proper appium-dotnet-driver NuGet package
28+
29+
Pen and multi-touch input support in Windows Application Driver is accessed using W3C WebDriver Actions API. Currently this feature is only supported
30+
through a temporary `WinAppDriver.Preview.Appium.WebDriver` instead of the official `Appium.WebDriver` NuGet package. This sample test
31+
is using this temporary NuGet package as shown in [packages.config](./packages.config).
32+
33+
To make use all the pen features through the library in the NuGet package above, use the `OpenQA.Selenium.Appium.Interactions.PointerInputDevice`
34+
instead of the `OpenQA.Selenium.Interactions.PointerInputDevice`.
35+
36+
37+
## Adding/Updating Test Scenario
38+
39+
Please follow the guidelines below to maintain test reliability and conciseness:
40+
1. Group test methods based on the relevant scenarios such as **Draw**
41+
2. Maintain original state after test runs and keep clean state in between tests when possible
42+
3. Only add tests that provide additional value to the sample

0 commit comments

Comments
 (0)