Testing Windows Store Apps with Coded UI Tests
Use coded UI tests to verify your Windows Store apps.
-
If you want to run coded UI tests for your XAML-based Windows Store app, you must set a unique automation property that identifies each control.
On the Tools menu, point to Options and then choose Text Editor, then XAML, and finally Miscellaneous.
Select the check box to automatically name interactive elements on creation.
-
Create a new project for a blank XAML based Windows Store app using either Visual C# or Visual Basic template.
-
In Solution Explorer, open MainPage.xaml. From the Toolbox, drag a button control and a textbox control to the design surface.
-
Double-click the button control and add the following code:
-
Press F5 to run your Windows Store app.
-
Create a new coded UI test project for the Windows Store app.
-
Choose to edit the UI map using the cross-hair tool.
-
Use the cross-hair tool in the Coded UI Test Builder to select the app tile, right-click AutomationId and choose Copy Value to Clipboard. The value in the clipboard will be used later for writing action to launch the app for testing.
-
In the running Windows Store app, use the cross-hair tool to select the button control and the textbox control. After adding each control, choose the Add control to UI control map button in the Coded UI Test Builder toolbar.
-
Choose the Generate Code button in the Coded UI Test Builder toolbar and then choose Generate to create code for changes to the UI control map.
-
Choose the button to set a value in the textbox.
-
Use the cross-hair tool to select the textbox control, and then select the Text property.
-
Add an assertion. It will be used in the test to verify that the value is correct.
-
Add and generate code for the assertion.
-
Visual C#
In Solution Explorer, open the UIMap.Designer.cs file to view the added code for the assert method and the controls.
Visual Basic
In Solution Explorer, open the CodedUITest1.vb file and then in the CodedUITestMethod1() test method code, right-click the call to the assertion method that was automatically added Me.UIMap.AssertMethod1() and choose Go To Definition. This will open the UIMap.Designer.vb file in the code editor so you can view the view the added code for the assert method and the controls.
Caution
Do not modify the UIMap.designer.cs or UIMap.Designer.vb file directly. If you do this, the changes to the file will be overwritten each time the test is generated.
Assert method
Controls
-
In Solution Explorer, open the CodedUITest1.cs or CodedUITest1.vb file. You can now add code to the CodedUTTestMethod1 method for the actions need to run the test using the controls added to the UIMap:
-
Launch the Windows Store app using the automation ID property you copied to the clipboard previously:
-
Add a gesture to tap the button control:
-
Verify that the call to the assert method that was automatically generated comes after launching the app and tap gesture on the button:
After adding the code, the CodedUITestMethod1 test method should appear as follows:
-
-
Build your test and then run the test using the test explorer.
The Windows Store app launches, the action to tap the button is completed, and the textbox’s Text property is populated and validated using the assert method.
After the test completes, the test explorer displays that the test passed.
-
Q: Why don’t I see the option to record my coded UI test in the Generate Code for a Coded UI Test dialog?
A: The option to record is not supported for Windows Store apps.
-
Q: Can I create a coded UI test for my Windows Store apps based on WinJS?
A: No, only XAML based apps are supported.
-
Q: Can I create coded UI tests for my Windows Store apps on a system that is not running Windows 8?
A: No, the Coded UI Test Project (Windows Store apps) template is only available on Windows 8.
-
Q: Why can’t I modify the code in the UIMap.Designer file?
A: Any code changes you make in the UIMapDesigner.cs file will be overwritten every time you generate code using the UIMap - Coded UI Test Builder. If you have to modify a recorded method, you must copy it to UIMap.cs file and rename it. The UIMap.cs file can be used to override methods and properties in the UIMapDesigner.cs file. You must remove the reference to the original method in the Coded UITest.cs file and replace it with the renamed method name.