This post is the Fourth post out of Four that builds the Visual Studio 2010 Coded UI Test User Guide. See the first post: “Visual Studio 2010 Coded UI Test User Guide – Introduction”, the second post: “Visual Studio 2010 Coded UI Test User Guide – Create A Simple Coded UI Test” and the third post: “Visual Studio 2010 Coded UI Test User Guide – Get A Coded UI Test Created In Manual Test Using The MTM Tool”
On this post I will show how to add validation rules to the Coded UI Test that we have previously recorded.
This post is based on the example made in the second post of this guide: “Visual Studio 2010 Coded UI Test User Guide – Create A Simple Coded UI Test”
Now that we have the code for the Coded UI Test we can add validation rules.
The validation rule I like to add will be placed after the last method of the test “this.UIMap.UpdateYourShoppingCart()” and I will call it: “CheckSubtotal”
Follow these steps to add this validation:
Step 1: Place the mouse cursor after the last method this.UIMap.UpdateYourShoppingCart() in the test.
Step 2: Right click choose “Generate Code for Coded UI Test” –> “Use Coded UI Test Builder…”
The Coded UI Test Recorder launched
Step 3: Drag the cursor to the object you like to validate, in this case the “Subtotal”
The ID of the object is shown
Step 4: Choose the property to validate and click: “Add Assertion”
A new window pops up with the assertions available.
Step 5: Choose the Comparator and the Comparison Value
Step 6: Click OK
You will see a mark next to the property indicate that a validation rule was added
Step 7: Click the “Generate Code” button
Step 8: Type the name of the method and click “Add and Generate” button
You can see that the method was added to the “TestMethod” and will run with the test.
You can see that it is easy to add validations to the test, use validations as much as you can.
I have also published a video that shows all the steps and examples from this guide: "Coded UI Test Demo – Video Hebrew"