Learn to use Visual Studio, Visual Studio Online, Application Insights and Team Foundation Server to decrease rework, increase transparency into your application and increase the rate at which you can ship high quality software throughout the application lifecycle
As part of Coded UI Test’s support for windows store apps introduced in Microsoft Visual Studio 2012 as detailed in this blog , there is now playback support for touch gestures on Windows Store Apps. These gestures are only a simulation and hence one would not need to have a touch monitor to use these API’s. Currently these API’s can only be used under the CUIT for Windows store project.
All the members in this family of Coded UI Test gesture API’s have two modes of operation so to speak:
In the former case the way a gesture searches for a control is similar to how a CodedUITest Mouse action does today. In the section that follows, we walkthrough each of the gesture API’s provided with examples. Please refer to the end of the blog post for a sample project demonstrating this support.
Gesture classification and walkthrough
The list of touch API’s can be broadly classified into two categories:
Before we proceed with the different gesture API’s provided and their usage it is important to understand the parameters that can be passed to them and their units.
Tap / Double Tap:
A tap simulates a left mouse button click.
// A simple tap on a button control. Gesture.Tap(button); // A tap at the bottom left part of the screen to bring up the start screen. A control-less gesture. Gesture.Tap(new Point(5, UITestControl.Desktop.BoundingRectangle.Height - 10));
A double tap on the other hand simulates a double click which can come into play in cases where one would need to select a word or depending on the app, magnify content.
// A double tap at a point inside a textbox control to highlight a word. Gesture.DoubleTap(textbox, new Point(10,10));
Press and Hold:
A press and hold gesture involves a single finger tap which extends for a given duration, the effect of which is similar to a right mouse click. This gesture is mostly used to bring up tool tips or context menus. For instance the following code brings up a context menu on an image control.
// A press and hold on an image control for a default duration of 1200 ms. Gesture.PressAndHold(imageControl);
A slide is used primarily for panning interactions but can also be used for drawing, moving or writing.
The values of the start and end points correspond to the coordinates on the screen or relative to a specified control. For instance a panning interaction from (200,300) to (400,300) will result in a slide from (200,300) for 200 pixels. In the following code sample the two slide actions have the same effect but each represents a mode of operation – Control and Control-less.
Point absoluteStartPoint = new Point(control.BoundingRectangle.Right -10, control.BoundingRectangle.Top + control.BoundingRectangle.Height/2); Point absoluteEndPoint = new Point(control.BoundingRectangle.Left + 10, control.BoundingRectangle.Top + control.BoundingRectangle.Height/2); Point relativeStartPoint = new Point(control.BoundingRectangle.Width - 10, control.BoundingRectangle.Height / 2); Point relativeEndPoint = new Point(10, control.BoundingRectangle.Height / 2); // A slide on the control for the default duration. Gesture.Slide(control, relativeStartPoint, relativeEndPoint); // A slide on absolute screen coordinates for the default duration (Control-less mode) Gesture.Slide(absoluteStartPoint, absoluteEndPoint);
A swipe is a short slide with the primary intention of selection. Swipe is always associated with a control and hence this is the only gesture that cannot be operated in a control-less mode.
// A swipe downwards on the control for a length of 40 pixels. Gesture.Swipe(selectableImageControl, UITestGestureDirection.Down, 40);
A flick gesture can be associated with a rapid slide in a scenario where one would quickly want to go through a long list of items. This gesture is characterised by its high speed.
Note: Although flick, slide and swipe seem similar they differ in their purpose of usage and are hence designed to be comfortably used for their appropriate objective.
Flick is fast if the gesture is to cover a large distance in a short duration and is slow if it is to cover a short distance for a long period of time. The below code snippet illustrates this on the start screen. Notice that as the duration of the gesture increase flick approaches slide.
Point relativeStartPoint = new Point(startScreen.BoundingRectangle.Width-100,startScreen.BoundingRectangle.Height/2); // A fast flick on the start screen. Gesture.Flick(startScreen, relativeStartPoint, (uint)startScreen.BoundingRectangle.Width / 2, UITestGestureDirection.Left, 2); // A relatively slower flick. Gesture.Flick(startScreen, relativeStartPoint, (uint)startScreen.BoundingRectangle.Width / 2, UITestGestureDirection.Left, 15);
Pinch/Stretch is essentially used for one of the following types of interactions: optical zoom, resizing or semantic zoom.
Note: Pinch never overshoots beyond the point of contact of the two touch points.
As an example the pinch gesture below performs a simple zoom out on an image control.
Point relativePoint1 = new Point(imageToZoom.BoundingRectangle.Width/4, imageToZoom.BoundingRectangle.Height/4); Point relativePoint2 = new Point(3 * imageToZoom.BoundingRectangle.Width/4, 3* imageToZoom.BoundingRectangle.Height/4); // A pinch on a control with each touch contact moving a 100 pixels towards each other. Gesture.Pinch(imageToZoom, relativePoint1, relativePoint2,100);
This gesture rotates a control in either clockwise or counter-clockwise direction.
Point relativePoint = new Point(imageToTurn.BoundingRectangle.Width - 10, 10); //Rotate an image about a focal point for 90 degrees clockwise. Gesture.Turn(imageToTurn, new Point(10, 10), relativePoint, 90);
Note: For a more generic scenario where one would want to rotate a control around its mid-point only the control and the angle of turn needs to be specified and the gesture logic takes care of the rest.
// Rotate the control around its midpoint for 180 degrees clockwise. Gesture.Turn(imageToTurn, 180);
This enumeration helps in easily specifying the 4 basic direction in which a gesture can be performed and has the following members:
Flick and swipe have overloads which accept this enumeration as a direction.
Is anyone actually using these touch based gestures for codedui? I have a feeling this is just a research project or is this more?
Support for touch gestures is part of the VS 2013 product. This is not a research project. Are you running into any issues that makes you believe otherwise?
When will this be available for WPF? This is what we would need...