Skip to content

Commit 668c852

Browse files
committed
Enhance Paint3DTest sample with W3C Actions interpolation feature
Draw a circle in pinch and zoom scenarios as visual aids Refactor Paint3DSession to increase test robustness
1 parent 44c2cdc commit 668c852

File tree

3 files changed

+112
-4
lines changed

3 files changed

+112
-4
lines changed

Samples/C#/Paint3DTest/Paint3DSession.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static void TearDown()
5555
// Close the application and delete the session
5656
if (session != null)
5757
{
58+
ClosePaint3D();
5859
session.Quit();
5960
session = null;
6061
}
@@ -73,6 +74,7 @@ public void CreateNewPaint3DProject()
7374
// Create a new Paint 3D project by pressing Ctrl + N
7475
session.SwitchTo().Window(session.CurrentWindowHandle);
7576
session.Keyboard.SendKeys(Keys.Control + "n" + Keys.Control);
77+
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
7678
DismissSaveConfirmDialog();
7779
}
7880
}
@@ -81,7 +83,21 @@ private static void DismissSaveConfirmDialog()
8183
{
8284
try
8385
{
84-
session.FindElementByAccessibilityId("CloseSaveConfirmDialog").FindElementByAccessibilityId("SecondaryBtnG3").Click();
86+
WindowsElement closeSaveConfirmDialog = session.FindElementByAccessibilityId("CloseSaveConfirmDialog");
87+
closeSaveConfirmDialog.FindElementByAccessibilityId("SecondaryBtnG3").Click();
88+
}
89+
catch { }
90+
}
91+
92+
private static void ClosePaint3D()
93+
{
94+
try
95+
{
96+
session.Close();
97+
string currentHandle = session.CurrentWindowHandle; // This should throw if the window is closed successfully
98+
99+
// When the Paint 3D window remains open because of save confirmation dialog, attempt to close modal dialog
100+
DismissSaveConfirmDialog();
85101
}
86102
catch { }
87103
}

Samples/C#/Paint3DTest/ScenarioDraw.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public void DrawWithPen()
8282
ActionSequence eraseSequence = new ActionSequence(penDevice, 0);
8383
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, A.X - 5, E.Y, TimeSpan.Zero));
8484
eraseSequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenEraser));
85-
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, B.X + 5, E.Y, TimeSpan.Zero));
85+
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, B.X + 5, E.Y, TimeSpan.FromSeconds(.5)));
8686
eraseSequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenEraser));
8787
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, E.X, C.Y, TimeSpan.Zero));
8888
eraseSequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenEraser));
89-
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, E.X, B.Y, TimeSpan.Zero));
89+
eraseSequence.AddAction(penDevice.CreatePointerMove(inkCanvas, E.X, B.Y, TimeSpan.FromSeconds(.5)));
9090
eraseSequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenEraser));
9191
session.PerformActions(new List<ActionSequence> { eraseSequence });
9292

Samples/C#/Paint3DTest/ScenarioZoom.cs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ public void ZoomingInMultiTouch()
7171
Assert.IsTrue(int.Parse(zoomScaleTextBox.Text) > 100);
7272
}
7373

74+
[TestMethod]
75+
public void ZoomingInMultiTouchWithInterpolation()
76+
{
77+
// Set pointer move Duration to 300 ms to implicitly generate 6 interpolation moves that are performed every 50 ms
78+
TimeSpan moveDuration = TimeSpan.FromMilliseconds(300);
79+
80+
// Drag a touch contact diagonally in NE direction distancing apart from the other contact point
81+
PointerInputDevice touch1 = new PointerInputDevice(PointerKind.Touch);
82+
ActionSequence touch1Sequence = new ActionSequence(touch1, 0);
83+
touch1Sequence.AddAction(touch1.CreatePointerMove(zoomInteractor, 50, -50, TimeSpan.Zero));
84+
touch1Sequence.AddAction(touch1.CreatePointerDown(PointerButton.TouchContact));
85+
touch1Sequence.AddAction(touch1.CreatePointerMove(zoomInteractor, 80, -80, moveDuration));
86+
touch1Sequence.AddAction(touch1.CreatePointerUp(PointerButton.TouchContact));
87+
88+
// Drag a touch contact diagonally in SW direction distancing apart from the other contact point
89+
PointerInputDevice touch2 = new PointerInputDevice(PointerKind.Touch);
90+
ActionSequence touch2Sequence = new ActionSequence(touch2, 0);
91+
touch2Sequence.AddAction(touch2.CreatePointerMove(zoomInteractor, -50, 50, TimeSpan.Zero));
92+
touch2Sequence.AddAction(touch2.CreatePointerDown(PointerButton.TouchContact));
93+
touch2Sequence.AddAction(touch2.CreatePointerMove(zoomInteractor, -80, 80, moveDuration));
94+
touch2Sequence.AddAction(touch2.CreatePointerUp(PointerButton.TouchContact));
95+
96+
// Perform the 2 fingers zoom in (expand) multi-touch sequences defined above
97+
session.PerformActions(new List<ActionSequence> { touch1Sequence, touch2Sequence });
98+
99+
// Ensure that the zoom level now is greater than 100%
100+
Assert.IsTrue(int.Parse(zoomScaleTextBox.Text) > 100);
101+
}
102+
74103
[TestMethod]
75104
public void ZoomingOutMultiTouch()
76105
{
@@ -107,6 +136,35 @@ public void ZoomingOutMultiTouch()
107136
Assert.IsTrue(int.Parse(zoomScaleTextBox.Text) < 100);
108137
}
109138

139+
[TestMethod]
140+
public void ZoomingOutMultiTouchWithInterpolation()
141+
{
142+
// Set pointer move Duration to 300 ms to implicitly generate 6 interpolation moves that are performed every 50 ms
143+
TimeSpan moveDuration = TimeSpan.FromMilliseconds(300);
144+
145+
// Drag a touch contact diagonally in SW direction approaching the other contact point
146+
PointerInputDevice touch1 = new PointerInputDevice(PointerKind.Touch);
147+
ActionSequence touch1Sequence = new ActionSequence(touch1, 0);
148+
touch1Sequence.AddAction(touch1.CreatePointerMove(zoomInteractor, 50, -50, TimeSpan.Zero));
149+
touch1Sequence.AddAction(touch1.CreatePointerDown(PointerButton.TouchContact));
150+
touch1Sequence.AddAction(touch1.CreatePointerMove(zoomInteractor, 20, -20, moveDuration));
151+
touch1Sequence.AddAction(touch1.CreatePointerUp(PointerButton.TouchContact));
152+
153+
// Drag a touch contact diagonally in NE direction approaching the other contact point
154+
PointerInputDevice touch2 = new PointerInputDevice(PointerKind.Touch);
155+
ActionSequence touch2Sequence = new ActionSequence(touch2, 0);
156+
touch2Sequence.AddAction(touch2.CreatePointerMove(zoomInteractor, -50, 50, TimeSpan.Zero));
157+
touch2Sequence.AddAction(touch2.CreatePointerDown(PointerButton.TouchContact));
158+
touch2Sequence.AddAction(touch2.CreatePointerMove(zoomInteractor, -20, 20, moveDuration));
159+
touch2Sequence.AddAction(touch2.CreatePointerUp(PointerButton.TouchContact));
160+
161+
// Perform the 2 fingers zoom out (pinch) multi-touch sequences defined above
162+
session.PerformActions(new List<ActionSequence> { touch1Sequence, touch2Sequence });
163+
164+
// Ensure that the zoom level now is less than 100%
165+
Assert.IsTrue(int.Parse(zoomScaleTextBox.Text) < 100);
166+
}
167+
110168
[ClassInitialize]
111169
public static void ClassInitialize(TestContext context)
112170
{
@@ -128,6 +186,40 @@ public void SetupZoomLevel()
128186

129187
// Ensure that the zoom level starts at 100%
130188
Assert.IsTrue(int.Parse(zoomScaleTextBox.Text) == 100);
189+
190+
// Draw a circle to help visualize the zoom level changes
191+
DrawCircle();
192+
}
193+
194+
private void DrawCircle()
195+
{
196+
// Draw a circle with radius 300 and 40 (x, y) points
197+
const int radius = 300;
198+
const int points = 40;
199+
200+
// Select the Brushes toolbox to have the Brushes Pane sidebar displayed and ensure that Marker is selected
201+
session.FindElementByAccessibilityId("Toolbox").FindElementByAccessibilityId("TopBar_ArtTools").Click();
202+
session.FindElementByAccessibilityId("SidebarWrapper").FindElementByAccessibilityId("Marker3d").Click();
203+
204+
// Locate the drawing surface
205+
WindowsElement inkCanvas = session.FindElementByAccessibilityId("InteractorFocusWrapper");
206+
207+
// Draw the circle with a single touch actions
208+
PointerInputDevice touchContact = new PointerInputDevice(PointerKind.Touch);
209+
ActionSequence touchSequence = new ActionSequence(touchContact, 0);
210+
touchSequence.AddAction(touchContact.CreatePointerMove(inkCanvas, 0, -radius, TimeSpan.Zero));
211+
touchSequence.AddAction(touchContact.CreatePointerDown(PointerButton.TouchContact));
212+
for (double angle = 0; angle <= 2 * Math.PI; angle += 2 * Math.PI / points)
213+
{
214+
touchSequence.AddAction(touchContact.CreatePointerMove(inkCanvas, (int)(Math.Sin(angle) * radius), -(int)(Math.Cos(angle) * radius), TimeSpan.Zero));
215+
}
216+
touchSequence.AddAction(touchContact.CreatePointerUp(PointerButton.TouchContact));
217+
session.PerformActions(new List<ActionSequence> { touchSequence });
218+
219+
// Verify that the drawing operations took place
220+
WindowsElement undoButton = session.FindElementByAccessibilityId("UndoIcon");
221+
Assert.IsTrue(undoButton.Displayed);
222+
Assert.IsTrue(undoButton.Enabled);
131223
}
132224
}
133-
}
225+
}

0 commit comments

Comments
 (0)