Skip to content

Commit 8fd6a08

Browse files
committed
Create a sample test to demonstrate pen actions using built-in Sticky Notes application
Add scenario to draw simple basic pen strokes as the main basic example Add scenario to draw strokes with extra attributes such as pressure, twist, and tilt angle Add scenario to erase previously drawn strokes using the pen eraser Create README.md to provide more details on how to perform various pen actions
1 parent f3e17d5 commit 8fd6a08

File tree

7 files changed

+645
-0
lines changed

7 files changed

+645
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 System.Reflection;
18+
using System.Runtime.CompilerServices;
19+
using System.Runtime.InteropServices;
20+
21+
[assembly: AssemblyTitle("StickyNotesTest")]
22+
[assembly: AssemblyDescription("")]
23+
[assembly: AssemblyConfiguration("")]
24+
[assembly: AssemblyCompany("")]
25+
[assembly: AssemblyProduct("StickyNotesTest")]
26+
[assembly: AssemblyCopyright("Copyright © 2018 Microsoft Corporation")]
27+
[assembly: AssemblyTrademark("")]
28+
[assembly: AssemblyCulture("")]
29+
30+
[assembly: ComVisible(false)]
31+
32+
[assembly: Guid("9ed00387-c536-4ad7-9228-9fb87d3a2fd7")]
33+
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Samples/C#/StickyNotesTest/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# StickyNotesTest
2+
3+
StickyNotesTest is a sample test project that demonstrates how to perform pen interactions through the actions API using the Windows 10 built-in **Sticky Notes** application.
4+
5+
This test project highlights some common pen interactions below.
6+
- Drawing using simple pen strokes
7+
- Drawing strokes with additional parameters such as pressure, twist, and tilt angles
8+
- Erasing previously drawn stroke by using eraser button
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 `StickyNotesTest.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+
## Tutorial
28+
29+
### Including proper appium-dotnet-driver NuGet package
30+
31+
Pen input support in Windows Application Driver is accessed using W3C WebDriver Actions API. Currently this feature is only supported
32+
through a temporary `WinAppDriver.Preview.Appium.WebDriver` instead of the official `Appium.WebDriver` NuGet package. This sample test
33+
is using this temporary NuGet package as shown in [packages.config](./packages.config).
34+
35+
To make use all the pen features through the library in the NuGet package above, use the `OpenQA.Selenium.Appium.Interactions.PointerInputDevice`
36+
instead of the `OpenQA.Selenium.Interactions.PointerInputDevice`.
37+
38+
### Drawing a pen stroke
39+
40+
A pen stroke is a collection of **PointerDown**, **PointerMove**, and **PointerUp** in an **ActionSequence** as shown below.
41+
```c#
42+
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
43+
ActionSequence sequence = new ActionSequence(penDevice, 0);
44+
45+
// Draw line AB from point A (0, 0) to B (10, 10)
46+
sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, 0, 0, TimeSpan.Zero));
47+
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact));
48+
sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, 10, 10, TimeSpan.Zero));
49+
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
50+
51+
session.PerformActions(new List<ActionSequence> { sequence });
52+
```
53+
54+
### Drawing with additional pen attributes
55+
56+
`OpenQA.Selenium.Appium.Interactions.PenInfo` class contains all the supported attributes for pen input such as **Pressure**, **Twist**,
57+
**TiltX**, and **TiltY**. An instance containing any of the attribute can be passed into any pointer event creation. For example:
58+
```c#
59+
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
60+
ActionSequence sequence = new ActionSequence(penDevice, 0);
61+
PenInfo penExtraAttributes = new PenInfo { TiltX = 45, TiltY = 45, Twist = 45 };
62+
63+
// Draw line AB from point A (0, 0) to B (10, 10) with attributes defined in penExtraAttributes
64+
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenContact, penExtraAttributes));
65+
sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Pointer, 10, 10, TimeSpan.Zero, new PenInfo { Pressure = 1f }));
66+
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenContact));
67+
68+
session.PerformActions(new List<ActionSequence> { sequence });
69+
```
70+
71+
### Erasing a pen stroke
72+
73+
When inking on a canvas, a pen stroke can be erased by drawing another stroke on top of it while depressing the **Eraser** button.
74+
Notice the use of `PointerButton.Eraser` instead of `PointerButton.PenContact`. For example:
75+
```c#
76+
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
77+
ActionSequence sequence = new ActionSequence(penDevice, 0);
78+
79+
// Erase line AB by pressing PenEraser (Pen tail end/eraser button) on the line AB
80+
sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, 0, 0, TimeSpan.Zero));
81+
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenEraser));
82+
sequence.AddAction(penDevice.CreatePointerMove(CoordinateOrigin.Viewport, 10, 10, TimeSpan.Zero));
83+
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenEraser));
84+
85+
session.PerformActions(new List<ActionSequence> { sequence });
86+
```
87+
88+
### Specifying pointer move coordinates
89+
90+
Windows Application Driver supports all W3C WebDriver pointer action **origins** as follows:
91+
1. **Viewport** - **X** and **Y** are relative to the application session window
92+
2. **Pointer** - **X** and **Y** are relative to the current **X** and **Y** position
93+
3. **Element** - **X** and **Y** are relative to the center point of the element
94+
95+
96+
## Adding/Updating Test Scenario
97+
98+
Please follow the guidelines below to maintain test reliability and conciseness:
99+
1. Group test methods based on the UI view page such as Alarm, Stopwatch, Timer, etc.
100+
2. Maintain original state after test runs and keep clean state in between tests when possible
101+
3. Only add tests that provide additional value to the sample

0 commit comments

Comments
 (0)