Export (0) Print
Expand All

Generating a Coded UI Test from an Existing Action Recording

Manual system tests can be automated. You can generate a coded test from recording of a manual test run created using Microsoft Test Manager, or you can link the test case to an existing coded test. The automated test can be run as part of a team build, and the results contribute to the reports of test cases in the same way as the manual test run.

Requirements

  • Visual Studio Ultimate or Visual Studio Premium

You’ll want to repeat system tests at regular intervals to make sure that recent development work hasn’t introduced bugs. But as the app gets bigger through the life of your project, more and more tests have to be performed. To avoid an impossibly big load of manual testing, it’s good to automate many of your tests.

As a general rule, manual tests are more effective for testing new features, and automated tests are better for verifying features that have already been tested manually.

There are two ways to automate manual test cases:

  • Generate a coded UI test from a recording of a manual test run. You can subsequently edit it. For example, you can run the test with multiple test data sets.

    Advantages of this method:

    • A test can be generated quickly.

    • The test code is an accurate representation of the manual actions.

    • The test includes the user interface and any logic that it contains.

    • Even if you’re more proficient in testing than you are in writing code, you can still create and edit the test.

    Disadvantages:

    • If the layout of the user interface is significantly changed, the test might become invalid. You might have to create it again, or edit the code that represents the actions.

  • Link the test case to existing test code. It can be any method that can be run by test explorer.

    Advantages:

    • This is the quickest way if an appropriate test method has already been developed along with the app code.

    • Changes in the user interface do not affect the test, because the test typically drives the app through the business layer.

    Disadvantages:

    • The test code might not accurately simulate the manual version of the test case. You have to make sure that the test code is an appropriate implementation of the intention of the test case.

You can also partially automate a test by recording a test run. On subsequent occasions, you can play back the recorded actions. But you have to be present so that you can verify the results of each step. See Record and play back manual tests.

In Visual Studio 2013, you create coded UI tests from action recordings using either Visual Studio Ultimate or Visual Studio Premium. Creating a coded UI test requires you to add a coded UI test project to your solution, after which you can easily add coded UI tests that are created from action recordings which are associated with work items. The steps to create these coded UI tests are described in ”Generate a Coded UI Test from an Action Recording” later in this topic.

Note Note

You can also create action recordings directly from either Visual Studio Ultimate or Visual Studio Premium by recording the app under development. See How to: Generate a Coded UI Test by Recording the Application Under Development.

Using Microsoft Test Manager, run the test case that you want to automate. When you start the test, be sure to select Create Action Recording. Work through the test. If you have to attend to something else in the middle of the test, use the Pause button to suspend the recording. Don’t worry if you make a mistake—simply repeat part of the sequence. You can edit out the incorrect actions later. When you have completed the test run, choose Save and Close to save the action recording.

For more information about how to create action recordings, see Record and play back manual tests.

Using Visual Studio, in Solution Explorer, right-click a coded UI test project, point to Add, and then choose Coded UI Test. After the Generate Code for a Coded UI Test dialog box displays, choose Use an existing action recording.

Create coded UI test from action recording

I don't see the option to add coded UI tests.

You might be using a version of Microsoft Visual Studio 2012 that does not support coded UI tests. To create coded UI tests, you must use either Visual Studio Ultimate or Visual Studio Premium.

Find existing action recording

Using the Work Items Picker dialog box, find the work item with an attached action recording.

When the coded UI test is generated, a method is created for each step in the test case from the action recording. For example, the code below calls three methods based on the steps that were in the action recording that was selected previously:

        [TestMethod]
        public void CodedUITestMethod1()
        {

            this.UIMap.Navigatetocart(); 
            this.UIMap.Changequantity(); 
            this.UIMap.Verifytotalchangescorrectly();

        }

Additionally, the UI controls are added to the UI map, and actions are added to your coded UI test.

What else should I know?

Notes

  • Prerequsite If you are not currently connected to a team project on a Team Foundation Server, when you try to create a coded UI test from an action recording, the Connect to Team Project dialog box appears. You must connect to a team project in order to view the work items containing the action recordings. See Connect to a team project from Team Explorer.

Tips

If you have test code that fulfills the intention of the test case, then you can associate the test case to that test method. Typically, the test might be an end-to-end functional test. It does not have to be a coded UI test.

Caution note Caution

If you are automating a test case that already has manual test steps, make sure that the code performs an equivalent test to the manual steps. It should fail in any case in which the manual test would fail.

You can only associate the automated Visual Studio system test with your manual test case using Visual Studio. You cannot make this association using Microsoft Test Manager. If you have an existing test case that you want to use, you must first open the test case using Visual Studio, as shown in the next illustration.

Open Test Case Using Microsoft Visual Studio

Then you can associate the test method with your test case, as shown in the next illustration.

Associate Automation With Test Case

For more information on associating a test case with an automated system test in Visual Studio, see Automate a test case in Microsoft Test Manager.

Show:
© 2014 Microsoft