Data Driven Coded UI Test using Visual Studio 11

Posted by: Gouri Sohoni , on 4/10/2012, in Category Visual Studio, VSTS & TFS
Views: 94263
Abstract: In this article, we will see how to convert normal Coded UI Test to Data Driven Coded UI Test using Visual Studio 11.

In this article, we will discuss in detail how to convert a normal Coded UI Test (CUIT) to Data Driven CUIT. CUIT is a new type of unit test introduced with Visual Studio 2010 Ultimate/Premium version. It provides functional testing for the user interface and the code gets created with the help of high level languages like C# or VB.NET.

If you are new to Coded UI Tests, make sure you read the following articles written for Visual Studio 2010.

Coded UI Test (CUIT) using Visual Studio 2010

Coded UI Test (CUIT) - Convert Manual Test Case to Code using Visual Studio 2010

Coded UI Test (CUIT) – Variations and Editing with Visual Studio 2010 and

Coded UI Test: Convert Normal CUIT to Data Driven CUIT using Visual Studio 2010.

Visual Studio 11 Beta can be downloaded from over here where all the SKUs (Ultimate, Premium, Professional or Test Professional) are available. Here is a snippet comparison between various SKUs and whether Coded UI Test support is available in them

vs11-compare-editions

The main difference while converting a normal CUIT to Data Driven CUIT with Visual Studio 11 is that there is no Data Source Wizard (which was available with Visual Studio 2010).

 

We will now create a normal CUIT and later convert it to Data Driven CUIT. For this we will use the example of a calculator and record addition of 2 numbers. We will use number keys to enter the numbers.

Follow these steps:

Step 1:  Open Visual Studio 11 > File > New Project.  A new project template for Coded UI Test project is available as shown

coded-ui-template

Step 2: As we are going to use the CUIT Builder, we will select the first radio button for creating a Coded UI Test (Record actions, edit UI map or add assertions)

record-actions

Step 3: The CUIT Builder with a slightly changed look appears in the default position (right most bottom portion of the screen)

ui-map

Step 4: Start Calculator

start-calulator

Step 5: Record addition of 2 numbers. Note: Do not use the mouse click to capture data as we do not get parameters with this action later

addition-coded-ui

Following are the methods recorded.

methods-recorded

We can also provide method description which will appear as a comment in the method

method-description

Step 6: With Visual Studio 11, we now have Unit Test Explorer which will show the available test methods. Run the test and verify that it gets executed without any error.

Step 7: Add a new item to the project. Provide NumData.xml as file name for the XML data file. Change the property for the file from Copy to Output Directory to “Copy if newer”

num-data

Step 8: We also need to provide the DataSource attribute to the method so as to specify the xml file as the data source. The parameters values can now to be taken from the data source as shown below

data-source-attribute

Step 9: Now run the test and we can observe that it passes for 2 records but fails for one.

coded-ui-test-result

Note: If you use a mouse click while entering numbers, no parameters will be automatically provided. This will also work only with single digit numbers.

In this article, we have seen how to convert normal Coded UI Test to Data Driven Coded UI Test using Visual Studio 11.

Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles
Gouri Sohoni is a Microsoft MVP, Trainer and consultant for over two decades. She is a Microsoft Certified Trainer (MCT), MCITP and has conducted several corporate trainings on Microsoft technologies that include Visual Studio 2010 (ALM), SQL Server 2008 BI, SQL Server 2008 developer track, SQL Server 2005 BI, SQL Server 2005 developer track etc.


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Sandeep K on Tuesday, November 6, 2012 6:37 AM
Hi Gouri Sohoni,

Could you please let me know the pros and cons of using an XML file as a data source against the SQL database.Will it impact the performance of the test case due to database interactions.
Thanks.
Comment posted by Hi Gouri Sohani on Wednesday, March 19, 2014 2:05 AM
Kindly let us know whether you are giving(or) providing any training on Coded UI for Desktop application.

--
Thanks.
Comment posted by sam on Wednesday, August 13, 2014 3:34 AM
Hi Gouri,
I am new to coded ui and i am planning to automate our application using coded ui. But i am little bit confused from where i have to start.
Is there any online training / book available.  

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel