- Create a Coded UI Test project.Coded UI tests must be contained in a coded UI test project. If you don’t already have a coded UI test project, create one. In Solution Explorer, on the shortcut menu of the solution, choose Add, New Projectand then select either Visual Basic or Visual C#. Next, choose Test, Coded UI Test.
- I don't see the Coded UI Test project templates.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.
- Add a coded UI test file.If you just created a Coded UI project, the first CUIT file is added automatically. To add another test file, open the shortcut menu on the coded UI test project, point to Add, and then choose Coded UI Test.In the Generate Code for Coded UI Test dialog box, choose Record actions, edit UI map or add assertions.The Coded UI Test Builder appears and Visual Studio is minimized.
- Record a sequence of actions.To start recording, choose the Record icon. Perform the actions that you want to test in your application, including starting the application if that is required.For example, if you are testing a web application, you might start a browser, navigate to the web site, and log in to the application.To pause recording, for example if you have to deal with incoming mail, choose Pause.To delete actions that you recorded by mistake, choose Edit Actions.To generate code that will replicate your actions, choose the Generate Code icon and type a name and description for your coded UI test method.
- Verify the values in UI fields such as text boxes.Choose Add Assertions in the Coded UI Test Builder, and then choose a UI control in your running application. In the list of properties that appears, select a property, for example, Text in a text box. On the shortcut menu, choose Add Assertion. In the dialog box, select the comparison operator, the comparison value, and the error message.Close the assertion window and choose Generate Code.
Tip Alternate between recording actions and verifying values. Generate code at the end of each sequence of actions or verifications. If you want, you will be able to insert new actions and verifications later. - View the generated test code.To view the generated code, close the UI Test Builder window. In the code, you can see the names that you gave to each step. The code is in the CUIT file that you created:
[CodedUITest] public class CodedUITest1 { ... [TestMethod] public void CodedUITestMethod1() { this.UIMap.AddTwoNumbers(); this.UIMap.VerifyResultValue(); // To generate more code for this test, select // "Generate Code" from the shortcut menu. } }
- Add more actions and assertions.Place the cursor at the appropriate point in the test method and then, on the shortcut menu, chooseGenerate Code for Coded UI Test. New code will be inserted at that point.
- Edit the detail of the test actions and the assertions.Open UIMap.uitest. This file opens in the Coded UI Test Editor, where you can edit any sequence of actions that you recorded as well as edit your assertions.
- Run the test.Use Test Explorer, or open the shortcut menu in the test method, and then choose Run Tests.
To see next post on Coded UI click this link