|
| 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