How To: Functional Testing Automation Using Visual Studio 2010

Syed Aslam Basha here from the Information Security Tools Team.

I want to share first hand experience of automating functional test cases using coded UI Test, a feature in visual studio (VS) 2010 in next few blog posts.

In this blog post let me show an example of recording a scenario of

  • launching web browser
  • open the portal site
  • Navigate in portal site
  • Close the browser

and playback using VS 2010.

    • Launch VS 2010
    • Select File –> New Project
    • Select Visual C#, Test and Test project, give appropriate project name as shown below and click on ok
    • image
    • This will create portal automation project along with default cs files
    • Right click on portalautomation project name and select add coded UI Test
    • image
    • It will launch Generate code for coded UI test select the first option and click on ok
    • image
    • A small form called coded UI test builder is shown at the right hand bottom cornerr of your screen. Now you can record actions, add assertion (we will discuss in upcoming blog posts) and generate code
    • image
    • Click on start recording button in the coded UI Test Builder, launch browser.
    • Type in the site name and press enter
    • Click on pause recording in Coded UI test Builder. You can view the steps recorded and edit by clicking on show recorded steps button in coded UI test builder
    • Click on Generate code, enter method name as “LaunchSite”. Its always a good practice to have modular reusable steps (we can record all steps till the end of the test case, but we will divide test steps into modular reusable components to increase reusability) You can call this function wherever required.
    • Click on start recording and record actions. Click on links in home page.
    • Click on pause recording in coded UI test builder. Click on Generate Code, enter appropriate method name.
    • Click on start recording and close the browser
    • Click on pause recording in coded UI test builder. Click on Generate Code, enter appropriate method name.
    • Lets see the code generated. You can see
 public void CodedUITest1()

            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items. this.UIMap.LaunchPortalSite();

  • Rename codedUITest1 to ValdiateHomePageLinks, to make it more meaningful and easy to understand. From your code you can clearly make out you are launching portal site, validating homepage links and closing thte site.
  • Press F5 or right click above launchportalsite method and select run tests to run/ playback.
  • You will see the output in test results as passed or failed.

-Syed Aslam Basha ( )

Microsoft Information Security Tools (IST) Team

Test Lead


Please leave a comment if the blog post has helped you.