Monday, September 27, 2010

Create a Simple Visual Studio 2010 Coded UI Test

In this blog, I’ll explain how to get up and running quickly on Coded UI Tests. This walk through will record a test that opens the “Calculator” program that comes with Windows.

The Coded UI Test functionality is available in Visual Studio 2010 Premium or Visual Studio 2010 Ultimate.

1. Open Visual Studio 2010

2. Go to File->New->Project

3. Create a new “Test Project” in Visual Studio 2010. I’ve named this one “CalcCodedUITest” under “C:\Projects”.




4. Click “OK”.

5. This will create the “Test Project” project with the following file structure:



6. Delete the UnitTest1.cs file and add a Coded UI Test by right clicking on the Project Name -> Add -> New Test and name the new test as “CalcTests.cs”



7. Click the “Cancel” button on the following screen:



8. Rename the “CodedUITestMethod1()” method to “LoadCalculator()”

9. Place the cursor in the “LoadCalculator” method and right click and select “Generate Code for Coded UI Test -> Use Coded UI Test Builder”



10. Click the record button to record the test



11. Type Windows Key + R

12. Type “Calc”

13. Click “OK”

14. Click the “Pause” button to pause the test



15. Click the “Show Record Steps” button to review the steps that it has recorded.



16. Your steps should look like the following:



17. Click the “Generate Code” button



18. Name your method. In this example, I named it “LoadCalc”



19. Click “Add and Generate” button

20. Now the “LoadCalculator” method is now populated with the “this.UIMap.LoadCalc();” statement.



21. Run the test by placing the cursor in the function, right click in the method and click “Run Tests”



22. If all worked correctly, the system would have loaded the “Calculator” application!

23. Congrats on creating and running your first GUI test!

Download Sample Coded UI Solution