Exercise 1: Introduction to Code Generation from Action Recordings

In this exercise, you will be introduced to the Visual Studio 2010 code generation features that allow testers to quickly and easily create coded UI tests directly from existing action recordings. Action recordings contain the steps taken during manual testing of an application. To learn more about manual testing and action recordings, please see the “Authoring and Running Manual Tests using Microsoft Test Manager” lab.

  1. Log in as Abu Obeida Bakhach (Dev) if you have not already done so. The password is P2ssw0rd (capital letter P, the number two, the letter s, the letter s, the letter w, the number zero, the letter r, and the letter d). Please see “Working with the Visual Studio 2010 Virtual Machine” for instructions on how to log into the VM.
  2. Open Microsoft Visual Studio from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  3. Start a new testing project (File | New | Project…).
  4. In the New Project window, select the Test Project template from Visual C# | Test and select the OK button to create the test project.

    Figure 1

    Creating a Test project

  5. Close the window showing UnitTest1.cs.
  6. In Solution Explorer, right-click on the TestProject1 project node and select Add | Coded UI Test… from the context menu.

    Figure 2

    Creating a Coded UI Test

  7. There are two ways to generate code for this new coded UI test. The first and default option is to use the Coded UI Test Builder, which allows you to generate test code by manually walking through a test scenario. The second option is to use an existing action recording. Select the second option to use an existing action recording and select the OK button to continue.

    Figure 3

    Using an existing action recording for test generation

  8. In the Work Items Picker window, select the Tailspin Toys project.
  9. In the Work Items Picker window, select the IDs radio button and enter 41. This is the ID of a test case in the Tailspin Toys project that contains an action recording.
  10. Select the Find button to execute the work item query. Note that for the purposes of this lab, we assume that the ID is already known.

    Figure 4

    Finding a test case with action recording

  11. Select the OK button to generate a coded UI test from the test case action recording.
  12. Navigate to the CodedUITestMethod1 method in the generated CodedUITest1.cs file. Each line represents a step from the action recording used during test generation.
  13. Right-click on the first method call in the CodedUITestMethod1 method and select Go To Definition. This will load the UIMap class from the UIMap.Designer.cs file which contains the generated test logic. This generated method launches Internet Explorer and navigates to a specified URL.

    Figure 5

    Navigating to test logic

  14. Scroll down to the ClickFourthCoffeeFlyer method within the UIMap class. This generated method tests clicking on a “Fourth Coffee Flyer” hyperlink that is in the Tailspin Toys Web application.

    Figure 6

    Generated test method example

  15. The ClickFourthCoffeeFlyer test method does not specify the hyperlink parameters directly, but rather refers to the “UIBlankPageWindowsInteWindow.UIHomeTailspinToysDocument1.UIFourthCoffeeFlyerHyperlink” property. Navigate to the definition of the UIFourthCoffeeFlyerHyperlink property to see how it is implemented.

    Figure 7

    Definition of SignInHyperlink property

    Note:
    The HtmlHyperlink instance that is created for the UIFourthCoffeeFlyerHyperlink property has a number of search and filter properties applied that aid the test framework in locating the correct HTML hyperlink. In the event that the Web application changes some of the link properties, such as the inner text, the test harness may still be able to find the hyperlink using the remaining search properties.
  16. Close the UIMap.Designer.cs file to return to the CodedUITest1.cs file.
  17. Right-click somewhere within the CodedUITest1.cs source file and select Run Tests. Important: do not touch the mouse or keyboard during the tests.

    Figure 8

    Location of Run Tests command

  18. As the tests run, an instance of Internet Explorer will be opened and actions automatically taken as they are defined in the coded UI test. The test will be run more than once because the original manual test that this coded UI test was generated from had multiple rows of test parameters.

    Figure 9

    Example of coded UI test running

  19. Verify that the test passed by viewing the Test Results window. In this case, however, we are not performing any validation after any of the steps.

    Figure 10

    Test Results window showing Passed test

Next Step

Exercise 2: Introduction to Code Generation using Coded UI Test Builder