[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
You can efficiently add an assertion for a UI control to verify that the application under test is working as expected, or you can add a UI control into a coded UI test, by using the Coded UI Test Builder.
Add UI Controls to a Coded UI Test
You can add a UI control for the application under test to the UI map and generate code to add the control to your coded UI test.
To add UI controls to a coded UI Test
In Solution Explorer, open a coded UI test source file from a test project in your solution.
To start the Coded UI Test Builder, right-click, point to Generate Code and then point to Use Coded UI Test Builder.
The Coded UI Test Builder dialog box appears.
Start your application under test and navigate to the UI control that you want to add.
To add a UI control to the UI map, drag the crosshairs to the UI control in your application that you want to test. When the box outlines your control, release the mouse.
The properties for this control are now listed in Coded UI Test Builder - Add Assertions dialog box. To locate the UI control in the map, click the arrow to view the UI control map.
Note |
|---|
You can also locate a UI control by pressing the Windows key and I. This is useful for a shortcut menu where the control is dismissed if you change focus to the crosshairs icon To find a parent, sibling, or child control, you can use the arrows in the dialog box. |
Click the add icon to add this control to the UI map.
Close the Coded UI Test Builder.
To generate the code to add the control to the UI map, click the Generate Code icon.
The Coded UI Test Builder - Generate Code dialog box is displayed.
Click Generate.
The UI control is now added to the UI map in your code.
(Optional) Use actions and apply them to the UI controls to move to a specific UI control to verify its properties by using Assert statements. For example, use the following code to click a button:
Add and Verify UI Controls in a Coded UI Test
You can add a UI control for the application under test to the UI map in your coded UI test, and then you can validate properties of the UI control when your test runs.
To add and verify controls in coded UI Test
In Solution Explorer, open a coded UI test source file from a test project in your solution.
To start the Coded UI Test Builder, right-click, point to Generate Code and then point to Use Coded UI Test Builder.
The Coded UI Test Builder dialog box appears.
Start your application under test and navigate to the UI control that you want to add.
To add a UI control to the UI map, drag the crosshairs to the UI control in your application that you want to test. When the box outlines your control, release the mouse.
The properties for this control are now listed in Coded UI Test Builder - Add Assertions dialog box. To locate the UI control in the map, click the arrow to view the UI control map.
Note |
|---|
You can also locate a UI control by pressing the Windows key and I. This is useful for a shortcut menu where the control is dismissed if you change focus to the crosshairs icon To find a parent, sibling, or child control, you can use the arrows in the dialog box. |
Click the add icon to add this control to the UI map.
Right-click the property that you want to verify, and then point to Add Assertion.
The Add assertion dialog box is displayed.
Select the Comparator for your assertion.
Type the value for your assertion in Comparison Value.
To add the assertion, click OK.
When you have added all your assertions for your test, close the Coded UI Test Builder - Add Assertions dialog box.
To generate the code for your assertions and add the control to the UI map, click the Generate Code icon.
The Coded UI Test Builder - Generate Code dialog box is displayed.
Type a name for your coded UI test method in Method Name, and then click Add and Generate.
This generates code as follows if the name that you entered is, for example, AssertForAddTwoNumbers:
public void AssertForAddTwoNumbers()
{
#region Variable Declarations
WinEdit textAnswerEdit = this.DemoCalculatorWindowWindow.AnswerWindow.TextAnswerEdit;
#endregion
// Verify that 'textAnswer' text box's property 'Text' equals '40'
Assert.AreEqual(this.AssertForAddTwoNumbersExpectedValues.TextAnswerEditText, textAnswerEdit.Text);
}
[TestMethod]
public void CodedUITestMethod1()
{
// To generate code for this test, select "Generate Code" from the shortcut menu and select one of the menu items.
this.UIMap.AddTwoNumbers();
this.UIMap.AssertForAddTwoNumbers();
}
When you choose a name for the method that has your assert statements, choose a name that is descriptive for these assertions that you created.
Tasks
Concepts
Other Resources