Intro
This is part 2 in a series of posts on creating and maintaining Coded UI tests with Multiple UI maps. My intent here is to give a little more detail to help those new to Visual Studio.
Part 1: Creating a new Coded UI solution
Part 2: Adding a New UI Map
Part 3: Modifying an Existing Coded UI Map
Part 4: Adding a UI Map to the TestRunUtility
Part 5: Assembling the test
Part 6: Changing Recorded Methods
Part 7: Deleting actions when recording with the Coded UI Test Builder
Part 8: Modifying Generated Code
This technique is an extension of the technique found in the following links by Anu , a Program Manager in the Visual Studio ALM Test Tools group and the MDSN documentation. http://blogs.msdn.com/b/anutthara/archive/2010/02/08/scaling-up-your-cuit-ui-automation-for-real-world-projects.aspx
http://blogs.msdn.com/b/anutthara/archive/2010/02/10/walkthrough-using-multiple-coded-ui-maps-in-test-automation.aspx
http://msdn.microsoft.com/en-us/library/ff398056.aspx
Planning the maps
Imagine this is our test case:
? Navigate to the Tail Spin Toy Site
? Click The Model Airplane Link
? Click the View Plane button next to the fourth coffee flyer
? Click the Add To cart button
? Review the shopping cart
What we want to do now is record the UI actions for several different pages in the Tailspin Toys website. If we look at the Tail Spin Toys example website we are going to interact with the following pages:
Home page ?

Model Airplanes Page -

Fourth Coffee Flyer Details page -

The Shopping Cart Page -

The pages are pretty simple so we are going to create a UI Map for each page. We could also create a UI Map for each control if our site reused many complex controls.
The first actions we want to record is Navigate to the home page and select the Model Airplanes button. So right click on the UI Maps folder and select Add -> New Item?

From the resulting dialog, select Coded UI Test Map, change the name to something meaningful like HomePageMap.uitest and click the Add button.

Notice the Coded UI Test Builder is launched and displayed in the lower right hand corner of your screen

The first thing we want to do is press record.
Then we will launch Internet Explorer
Type in the address: http://win-gs9gmujits8:8000 and click the enter key.
Click the show recorded steps button and you should see the following (note: if about:blank is not your home page, you may see a different initial web page and you could see differences if you click a short cut or use copy paste. Generally speaking you should type in the address for the recording)

Click the generate Code button and add a method name as NavigateToTailspinToysSite
, then click Add and Generate

Next click record again and click on the Model Airplanes button then click the Generate Code Button and enter NavigateToModelAirplanes

At this point we have generated a UI map for the things we are interested in on this ?home page?. If we take a look at the solution we will see 3 files.
HomePageMap.uitest ? this is an xml file that should only be edited by double clicking on this file and using the UI Map Editor (must have VS 2010 feature pack 2 to use the editor)
HomePageMap.cs ? This file contains custom code and may be hand edited. It will be blank right now.
HomePageMap.Designer.cs ? This file contains generated code. Do not edit this file as you changes will be overwritten any time visual studio regenerates this file.

Click here for the MSDN Documentation.
Now we want to generate the UI map for our Model Airplanes Page. The key here is that we do not want or need to launch internet explorer again so before recording we will open IE -> navigate to the tailspin toys site -> click on the Model Airplanes button. Your browser should look like this:

The only control we are really interested in here is the View Plane button for the Fourth Coffee Flyer.
To create the UI Map, right click on the UI Maps folder and select Add -> New Item?

From the resulting dialog, select Coded UI Test Map, change the name to something meaningful like ModelAirplanePageMap.uitest and click the Add button.
Again, the Coded UI builder is launched. Click the record button -> Click the View Plane button for the Fourth Coffee Flyer and click generate code.

Enter ViewFourthCoffeeFlyer and click Add andGenerate.
Close the coded UI Builder.
That brings us to the next page which I have chosen to call Fourth Coffee Flyer Details page. On this page we are interested only in adding a Fourth Coffee Flyer to the cart. Again go to solution explorer in visual studio, right click on the UI Maps folder and select Add -> New Item?

From the resulting dialog, select Coded UI Test Map, change the name to something meaningful like FourthCoffeeFlyerDetailsPageMap.uitest and click the Add button. Again, the Coded UI Test builder is launched.
Without recording we need to open IE -> navigate to the tailspin toys site -> click on the Model Airplanes button -> Click the View Plane button for the Fourth Coffee Flyer. Now we are on the Fourth Coffee Flyer Details page so we can click the record button -> Click the Add to Cart Button -> Click the Generate Code Button and type in the name AddFourthCoffeeFlyerToCart -> click Add and Generate.

Close the Coded UI test builder and your project in solution Explorer should now look like this:

We are almost done with the UI Map generation. For our final page we are going to validate some information on our Shopping Cart Page. Again go to solution explorer in visual studio, right click on the UI Maps folder and select Add -> New Item?

From the resulting dialog, select Coded UI Test Map, change the name to something meaningful like ShoppingCartPageMap.uitest and click the Add button. Again, the Coded UI Test builder is launched. Without recording we need to open IE -> navigate to the tailspin toys site -> click on the Model Airplanes button -> Click the View Plane button for the Fourth Coffee Flyer -> Click Add to Cart.
There is no need to press record this time as all we want to do is add an assertion. With your mouse pointer over the Assert button click and hold the left mouse button down while dragging the cursor over the text box that contains the quantity 1 outlined in blue then release the mouse button.

You should now see something similar to this in the lower left corner of your screen:

Scroll down until you see the text attribute, then highlight that row by clicking the word text and click the add assertion button.

Accept the defaults -> click OK.

Now click the generate code button and enter AssertQuantity and click the Add and Generate Button.
What we have just done is generated code that says ?validate that the quantity input box has a text value of ?1?.
Two more steps, first we are going to clear the cart so press Record on the Coded UI builder -> Click Remove -> Click Generate Code -> Enter RemoveItemFromCart for the name -> Click Add and Generate.
The final thing we want to do is close the Browser. This is important as eventually these tests should be automated and run as part of a build. During the test run we don?t want to have multiple browsers open 1) because eventually we will run out of memory and 2) this can really mess up our tests depending how the site manages session.
I think a more intuitive place to close the browser is from the home page so we are going to close the coded UI test builder and in the next post we will see how to modify an existing Coded UI Test Map.
e6c8a79c-1550-4ad3-a8ea-819ee277a5c6|4|4.8