You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Blend for Visual Studio, you can select an option to assign unique names to interactive elements such as buttons, list boxes, combo boxes, and text boxes. This gives the controls unique values for **AutomationProperties.Name**.
Copy file name to clipboardExpand all lines: docs/test/test-uwp-app-with-coded-ui-test.md
+31-37Lines changed: 31 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -21,21 +21,23 @@ This article explains how to create a coded UI test for a Universal Windows Plat
21
21
22
22
The first step is to create a simple UWP app to run the test against.
23
23
24
-
1. In Visual Studio, create a new project using the **Blank App (Universal Windows)** template for Visual C# or Visual Basic template.
24
+
1. In Visual Studio, create a new project using the **Blank App (Universal Windows)** template for Visual C# or Visual Basic.
25
25
26
26

27
27
28
28
1. In the **New Universal Windows Platform Project** dialog, select **OK** to accept the default platform versions.
29
29
30
30
1. From **Solution Explorer**, open *MainPage.xaml*.
31
31
32
+
The file opens in the **XAML Designer**.
33
+
32
34
1. Drag a button control and a textbox control from **Toolbox** to the design surface.
33
35
34
36

35
37
36
-
1. Give names to the controls. Select the textbox control and in the **Properties** window, enter **textBox** in the **Name** field. Then, select the button control and in the **Properties** window, enter **button** in the **Name** field.
38
+
1. Give names to the controls. Select the textbox control, and then in the **Properties** window, enter **textBox** in the **Name** field. Select the button control, and then in the **Properties** window, enter **button** in the **Name** field.
37
39
38
-
1. Double-click the button control and add the following code to the body of the `Button_Click` method. This code sets the text in the textbox to the name of the button control.
40
+
1. Double-click the button control and add the following code to the body of the `Button_Click` method. This code simply sets the text in the textbox to the name of the button control, just to give us something to verify with the coded UI test we'll create later.
39
41
40
42
```csharp
41
43
this.textBox.Text=this.button.Name;
@@ -65,7 +67,7 @@ The first step is to create a simple UWP app to run the test against.
65
67
66
68
1. Open the **Coded UI Test Builder** dialog by placing the cursor in the `CodedUITestMethod1` method and then choosing **Test** > **Generate Code for Coded UI Test** > **Use Coded UI Test Builder**.
67
69
68
-
1. Use the **Coded UI Test Builder** cross-hair tool to select the button control in the UWP app. In the **Add Assertions** dialog, expand the **UI Control Map** pane if necessary, and then select **Add control to UI Control Map**.
70
+
1.Add the controls to the UI control map. Use the **Coded UI Test Builder** cross-hair tool to select the button control in the UWP app. In the **Add Assertions** dialog, expand the **UI Control Map** pane if necessary, and then select **Add control to UI Control Map**.
69
71
70
72

71
73
@@ -75,27 +77,25 @@ The first step is to create a simple UWP app to run the test against.
75
77
76
78

77
79
78
-
1.Click the button to verify that the text in the textbox is set to **button**.
80
+
1.To verify that the text in the textbox changes to **button** when the button is clicked, click the button.
79
81
80
82

81
83
82
-
1. Use the cross-hair tool to select the textbox control, and then select the **Text** property in the **Add Assertions** dialog.
83
-
84
-
1. In the **Add Assertions** dialog, select **Add Assertion** or press **Alt**+**A**. The assertion verifies that the text value is correct. In the **Message on Assertion Failure** box, enter **Textbox value is unexpected.** and then select **OK**.
84
+
1. Add an assertion to verify the text in the textbox control. Use the cross-hair tool to select the textbox control, and then select the **Text** property in the **Add Assertions** dialog. Then, select **Add Assertion** or press **Alt**+**A**. In the **Message on Assertion Failure** box, enter **Textbox value is unexpected.** and then select **OK**.
85
85
86
86

87
87
88
-
1. In the **Coded UI Test Builder** dialog, select **Generate Code** to generate code for the assertion. In the **Generate Code** dialog, select **Add and Generate**.
88
+
1.Generate test code for the assertion. In the **Coded UI Test Builder** dialog, select **Generate Code**. In the **Generate Code** dialog, select **Add and Generate**.
89
89
90
90

91
91
92
-
1. In **Solution Explorer**, open *UIMap.Designer.cs* to view the added code for the assert method and the controls.
92
+
In **Solution Explorer**, open *UIMap.Designer.cs* to view the added code for the assert method and the controls.
93
93
94
94
> [!TIP]
95
-
> If you're using Visual Basic,open *CodedUITest1.vb*. Then, in the `CodedUITestMethod1()` test method code, right-click on the call to the assert method (`Me.UIMap.AssertMethod1()`) and choose **Go To Definition**. *UIMap.Designer.vb* opens in the code editor so you can view the added code for the assert method and the controls.
95
+
> If you're using Visual Basic,open *CodedUITest1.vb*. Then, in the `CodedUITestMethod1()` test method code, right-click on the call to the assert method `Me.UIMap.AssertMethod1()` and choose **Go To Definition**. *UIMap.Designer.vb* opens in the code editor, and you can view the added code for the assert method and the controls.
96
96
97
97
> [!WARNING]
98
-
> Do not modify the *UIMap.designer.cs* or *UIMap.Designer.vb* files directly. If you do, the changes to the file will be overwritten when the test is generated.
98
+
> Do not modify the *UIMap.designer.cs* or *UIMap.Designer.vb* files directly. If you do, your changes will be overwritten when the test is generated.
99
99
100
100
The assert method looks like this:
101
101
@@ -127,31 +127,29 @@ The first step is to create a simple UWP app to run the test against.
127
127
128
128

Replace the automation ID in the example code with the value you copied to the clipboard in the previous step.
143
141
144
-
> [!IMPORTANT]
145
-
>TrimthebeginningoftheautomationIDtoremovecharacterssuchas**P~**. Ifyoudon't trim these characters, the test throws a `Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException` when it tries to launch the app.
142
+
> [!IMPORTANT]
143
+
> Trim the beginning of the automation ID to remove characters such as **P~**. If you don't trim these characters, the test throws a `Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException` when it tries to launch the app.
@@ -189,7 +187,7 @@ The first step is to create a simple UWP app to run the test against.
189
187
190
188
1. Select **Run All** to run the test.
191
189
192
-
The app opens, the button tap gesture executes, and the textbox's **Text** property is populated. The assert methods validates the textbox's **Text** property.
190
+
The app opens, the button is tapped, and the textbox's **Text** property is populated. The assert method validates the textbox's **Text** property.
193
191
194
192
After the test completes, **Test Explorer** displays that the test passed.
195
193
@@ -205,15 +203,11 @@ The first step is to create a simple UWP app to run the test against.
205
203
206
204
**A**: No, only XAML-based apps are supported.
207
205
208
-
### Q: Can I create coded UI tests for my UWP apps on a system that is not running Windows 8.1 or Windows 10?
209
-
210
-
**A**: No, the Coded UI Test Project templates are only available on Windows 8.1 and Windows 10. To create automation for Universal Windows Platform (UWP) apps, you'll need Windows 10.
211
-
212
206
### Q: Why can't I modify the code in the UIMap.Designer file?
213
207
214
-
**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 the *UIMap.cs* file and rename it. The *UIMap.cs* file can be used to override methods and properties in the *UIMapDesigner.cs* file. Remove the reference to the original method in the *CodedUITest.cs* file and replace it with the renamed method name.
208
+
**A**: Any code changes you make in the *UIMapDesigner.cs* file are overwritten every time you generate code using the **Coded UI Test Builder**. If you have to modify a recorded method, copy it to the *UIMap.cs* file and rename it. The *UIMap.cs* file can be used to override methods and properties in the *UIMapDesigner.cs* file. Remove the reference to the original method in the *CodedUITest.cs* file and replace it with the renamed method name.
215
209
216
210
## See also
217
211
218
-
-[Use UI automation to test Your code](../test/use-ui-automation-to-test-your-code.md)
212
+
-[Use UI automation to test your code](../test/use-ui-automation-to-test-your-code.md)
219
213
-[Set unique automation properties for UWP controls](../test/set-a-unique-automation-property-for-windows-store-controls-for-testing.md)
0 commit comments