Visual Studio 2010 Coded UI Test User Guide – Add Validation To Your Coded UI Tests

מאי 16, 2010


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…”


Step_1__Launch_Recorder


The Coded UI Test Recorder launched


Step_2__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_3_Check_the_subtotal


Step 4: Choose the property to validate and click: “Add Assertion”


 Step_4_Add_assertion_on_a_field


A new window pops up with the assertions available.


Step 5: Choose the Comparator and the Comparison Value


Step 6: Click OK


 Step_5_check_subtotal


You will see a mark next to the property indicate that a validation rule was added


 Step_6_result


Step 7: Click the “Generate Code” button


 Step_7_generate_method


Step 8: Type the name of the method and click “Add and Generate” button


 Step_8_generate_method


You can see that the method was added to the “TestMethod” and will run with the test.


 Step_9_added_method


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"


Have Fun!!!

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

תגובה אחת

  1. Sachinספטמבר 29, 2010 ב 16:19

    hi .. I am interested in knowing whether VSTS2010 web tests support. Validation testing . for example I have an employeesave page that has Firstname and Lastname as mandatory fields. if user clicks on save button and fields firstname and lastname are not entered then it gives message saying please enter firstname and lastname .. Does VSTS 2010 supports this testing ?

    הגב