Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Testing Applications by Using the Surface Simulator Automation API

Surface 1.0 SP1

The Surface Simulator Automation API (Microsoft.Surface.Simulator.Automation) enables you to programmatically simulate contact input for Microsoft Surface. The Surface Simulator Automation API enables you to directly manipulate Microsoft Surface applications that you are testing by using SimulatedContact objects.

This example describes how to set up an automated test of an application that is running in Surface Simulator by using a Windows Forms project.

Creating the Test Driver Application

  1. Start Microsoft Visual C# or Microsoft Visual Studio, and create a new Windows Forms project:

    1. On the File menu, click New Project.

    2. Under Project Types, click Visual C#.

    3. In the right side under Templates, click Windows Forms Application.

    4. Set the Name of the project to "MySimulatorAutomationTest", and then click OK.

  2. Add references to the project to Microsoft.Surface.Core and Microsoft.Surface.Simulator.Automation.SimulatorAutomation:

    1. In the Solution Explorer pane, right-click References, and then click Add Reference.

    2. In the .NET tab, double-click Microsoft.Surface.Core.

    3. Right-click References again, and then click Add Reference.

    4. In the .NET tab, double-click SimulatorAutomation.

  3. In the Visual Studio Solution Explorer window, right-click Form1.cs, and then click View Code. Add using statements in the Form1.cs file.

  4. In the Form1.cs [Design] tab, resize the form to be slightly wider than the width of a default button control.

  5. Set the Text property of the form to "Test Driver" in the Form1.InitializeComponent method.

  6. Open the Toolbox pane (on the View menu, click Toolbox), and then add a button control to the form named btnRunTest that displays the text "Run Test".

    Surface Simulator - Automation API test example
  7. Add test driver code by double-clicking the button in the Form1.cs [Design] tab to display the button-click event handler code segment and then modifying the code as follows (note that the event handler method will be named buttonName_Click, where buttonName is the name that you specified for the button).

  8. Add a new SimulatorAutomationAPI class in your project. This class encapsulates the Surface Simulator Automation API driver code, keeping it separate from the user in interface. It exposes one method, AnimateRandomContact, to perform the automation. The following code shows the SimulatorAutomationAPI class.

    Adding more than 200 contacts by using SimulatedContactCollection might produce unpredictable results. Limit the number of simulated contacts to 200.

Running the Test

To see your automated test driver code in action:

  1. Compile and run the application, by pressing F5 in Visual C# or Visual Studio, but do not click the Run Test button. You can also run the test driver application outside of the Visual Studio environment.

  2. If you are running your test on a Microsoft Surface unit, make sure Surface Input and Surface Shell are running.

  3. Open Surface Simulator by clicking Start, clicking All Programs, clicking Microsoft Surface SDK 1.0 SP1, clicking Tools, and then clicking Surface Simulator.

  4. When Surface Simulator is running, start an application from Launcher.

  5. In the test driver window, click the Run Test button.

The following illustration shows the Data Visualizer sample with the Surface Simulator and test driver application running on a Microsoft Surface unit.

Surface Simulator - in Data Visualizer sample

The visual results of your automated test depend on the application that you select in step 4.

Community Additions

© 2015 Microsoft