How to: Generate a Coded UI Test from an Action Recording

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

Using an existing action recording is an efficient way to create coded UI tests. For more information about how to create action recordings, see Recording and Playing Back Manual Tests.

Generate a Coded UI Test from an Action Recording

To generate a coded UI test from an action recording

  1. In Solution Explorer, right-click a test project, point to Add, and then click Coded UI Test.

    - or -

    In the Test List Editor or the Test View window, right-click the surface of the window and then click New Test. In the Add New Test dialog box, click Coded UI Test and then click OK.

    - or -

    On the Test menu, click New Test. In the Add New Test dialog box, click Coded UI Test and then click OK.

    The Coded UI Test dialog box appears.

  2. Click Use an existing action recording.

    The Connect to Team Project dialog box appears.

  3. Find the work item with an attached action recording:

    1. Select your project in the Project drop-down list and click Connect.

    2. Choose a method to find a work item with an attached action recording: Execute a saved query, query by ID, or search by the title of the work item.

    3. Click Find to execute the query.

  4. Select the work item with the action recording you want to use to create a coded UI test, and then click OK.

    This adds the UI controls to the UI map, and actions to your coded UI test. A method is created for each step in the test case for the action recording.

  5. To generate assertions for your UI controls, right-click in the coded UI test source file, point to Generate Code and then point to Use Coded UI Test Builder.

    The Coded UI Test Builder dialog box appears.

  6. Start your application under test and navigate to the UI control that you want to add.

  7. Click the crosshairs icon in the Coded UI Test Builder and drag it to the control that you want to verify is correct.

    The Coded UI Test Builder - Add Assertions dialog box is displayed.

  8. Click the vertical bar to view the UI map.

    The UI control that you want to verify should be highlighted.

  9. Right-click the property for the UI control that you want to verify, and then point to Add Assertion.

    The Add assertion dialog box is displayed.

  10. Select the Comparator for your assertion.

  11. Type the value for your assertion in Comparison Value.

  12. To add the assertion, click OK.

  13. When you have added all your assertions for your test, close the Coded UI Test Builder - Add Assertions dialog box.

  14. To generate the code for your assertions, click the Generate Code icon.

    The Coded UI Test Builder - Generate Code dialog box is displayed.

  15. 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:

    • Adds a method called AssertForAddTwoNumbers to the UIMap.Designer.cs file. This method performs the assert statements that you added.

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);
        }

  • Adds a call to the assert method AssertForAddTwoNumbers to the test method in your coded UI test file

[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.

For more information about action recordings, see How to: Create an Action Recording.

See Also

Tasks

Concepts

Other Resources

Page view tracker