How to: Add Validation Code to Your Coded UI Test
This page is specific to:.NET Framework Version:
4
How to: Add Validation Code to Your Coded UI Test

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Validation code can analyze the results of a test to determine whether the application performed as expected without the need for human intervention.

Add Validation Code to Your Coded UI Test

To add validation code to your coded UI Test

  1. Right-click inside your coded UI test method, point to Edit CodedUITest, and then click Use the UI Control Locator.

    NoteNote

    When you use the UI Control Locator tool to add validation, the UI control for this UI test control must be visible in your application under test. If it is not visible, the UI Control Locator will be unable to locate the control.

  2. If your UI control is already listed in the Add Assertion tab of the Coded UI Test Builder dialog box, click to select that UI control.

    If your UI control is not listed:

    1. Click Launch Locator to Add UI Controls.

    2. Use the crosshairs to select the UI control in your application.

    3. Click Add Control.

    4. Click Close.

    5. Click to select your UI control.

  3. To display the properties that you can validate for this UI test control, click Show Properties to Add Assertions or press F4.

  4. Select the properties that you want to validate, and then select the comparator operation and the comparison value for each property.

  5. To generate the validation code for the selected properties, click OK.

    This adds the code for the Assert statement into the test method.

    NoteNote

    If the comparison in the Assert statement fails when the test runs, then the test will fail.

You can also add Assert statements manually to your code to validate properties of UI test control. For example, to compare if the expected value equals the actual value of testElement1:

string testElementValue = testElement1.GetProperty("Value").ToString();
Assert.AreEqual(expectedValue, testElementValue);
See Also

Tasks

Concepts

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View