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

Posted by: Gouri Sohoni , on 5/22/2011, in Category Visual Studio, VSTS & TFS
Views: 51923
Abstract: In this article, we will discuss another way of creating Coded UI Test CUIT i.e. by using the recording created with the help of Microsoft Test Manager 2010 in Visual Studio 2010.

In our last article Coded UI Test (CUIT) using Visual Studio 2010 we discussed the architecture of Coded UI Test and how CUIT can be created by recording the actions and adding assertions. In this article, we will discuss one more way of creating CUIT, i.e. by using an existing action recording.

To create an action recording, we need to first create a Test Case and execute it manually with the help of Microsoft Test Manager 2010. Test Case is a new work item added with Team Foundation Server 2010. Test Case comprises of steps, steps can have actions and expected results. We will now start by creating a Test Case by using Microsoft Test Manager 2010 (MTM). The main difference between working with Visual Studio 2010 and MTM is that with MTM, we are always working in a connected environment. We are always connected to TFS 2010 when working. However with VS 2010, we can work only on the client side (without connected to TFS) if required.

In this article, we will see the following:

  • How to create a Test Case
  • Execute it using Microsoft Test Runner
  • Record actions
  • Convert these actions to its code equivalent by using Visual Studio 2010
  • Execute test from VS
  • How to associate automation back to test case.

 

Step 1: Start Microsoft Test Manager 2010 from the Visual Studio 2010 list of features. MTM 2010 gets automatically installed with VS 2010 Ultimate version. There is a separate installable for Microsoft Test Professional 2010 too. MTM connects to TFS as follows:

cuit-mtm-connect-tfs

Enter the TFS name in the textbox and click on Add button.

Step 2: The list of available collections and respective projects from the server will be shown after connecting to the Team Foundation Server 2010. The 2 process templates supported with TFS are Agile and CMMI. The screen looks as follows:

cuit-mtm-collections-list

We can select Connect now after selecting the project name. Here we can see 3 collections in TFS VS2010 with the named DefaultCollection, Demo Collection and DemoWithReports and many projects in DefaultCollection. Each created collection creates a database in turn in SQL Server 2008.

Step 3: Once the project is selected, we can select an existing test plan or add a new one. All the testing related artifacts will be associated with the test plan

cuit-mtm-testplan

Step 4: You can view the 4 tabs in Testing Centre namely Organize, Plan, Test and Track. Select Organize tab > select Test Case Manager from it and then select New Test Case. Enter following details for the test case:

cuit-testcase-creation

 

Step 5: Now that we have created test case and added steps to it, let us execute the test case with the help of Microsoft Test Runner.

cuit-mtm-testcase-run

The screen for execution looks as follows. The left hand side shows the steps and the expected result, while the remaining portion is where actual execution can be done. We will execute the test by using default setting for data adapters.

cuit-mtm-execute-testcase

 

Step 6: Now that the test has been successfully executed, let us convert the recorded steps to its code equivalent by using Visual Studio 2010. Start VS 2010 > select test project created in previous example and add Coded UI Test template to it.

cuit-generatecode

Select the radio button for using existing recording. The query window will appear as follows:

cuit-manual-query Provide either the work item id or execute query to find the test case which has the recording and select it.

Step 7: The code gets added as follows.

cuit-code-manual-recording

 

Step 8: Part of the code added in UIMap.Designer.cs looks as follows:

cuit-def-code-manualrecording We can view two of these methods which can be seen from previous step.

Step 9: The added CUIT method can now be executed from Visual Studio 2010. Let us open the work item for test case and specify the code for the Associated Automation tab.

cuit-associate-automation

As you can observe, the .cs file gets associated and the Automation Status also changes.

Step 10: After changing the work item of type test case by specifying, we can even execute this automated test case from Microsoft Test Manager. The prerequisite for this kind of execution is that the Test Agent must be running in the Interactive Process mode and not as Windows Service. This is required as there are some interactions with the desktop. Secondly the computer on which the Coded UI Test is running, cannot be locked.

Conclusion

In this article, we discussed another way of creating CUIT i.e. by using the recording created with the help of Microsoft Test Manager 2010. In the next article, we will discuss some variations with CUIT like adding multiple UI Maps and also how the CUIT editor can be used.

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 Kavitha on Wednesday, November 16, 2011 6:40 AM
In the Step:6 how to add the Coded UI Template,please help me on this
Comment posted by Naresh on Friday, January 6, 2012 12:01 AM
Hi Gouri,

i have created coded ui testing using VS2010,how can i configure these testing for ruuning auotmatically one by one in TFS server.

Regards,
Naresh.P
Comment posted by Gouri Sohoni on Friday, April 13, 2012 12:11 AM
Hi Naresh,
Sorry for delay in reply. You can configure these tests to run automatically using Microsoft Test Manager MTM, please follow the link for creating and using associated automation and creating a physical environment with MTM from http://www.ssgsonline.com/AutoTesting.aspx
Comment posted by Naveen on Friday, April 20, 2012 1:51 AM
Hello Gouri,

Can you please share startup tutorials for codedUI biggners. I have worked lot on performance using VSTS however codedUI is new for me and want to explore more on this area.

Please help.

Thanks,
Naveen
Comment posted by Gouri Sohoni on Tuesday, April 24, 2012 1:46 AM
Hi Naveen,
Start up videos can be seen from http://www.ssgsonline.com/AutoTesting.aspx
Comment posted by Naveen on Wednesday, April 25, 2012 5:50 AM
Thanks Gauri.
Comment posted by lakshmi on Wednesday, June 20, 2012 1:58 PM
hi gouri

is it possible to convert the ui coded test in vs to mtm

Comment posted by Gouri Sohoni on Friday, June 29, 2012 2:38 AM
Hi Lakshmi,
Please refer to the video for associate automation from http://www.ssgsonline.com/AutoTesting.aspx
Comment posted by Sara S on Friday, January 18, 2013 8:35 AM
Once you have a recorded action associated to a coded UI test and you update/overwrite the action recording from Test Manager - how do you get the Coded UI test to use the new recording??
Comment posted by Sara S on Friday, January 18, 2013 8:46 AM
Once you have a recorded action associated to a coded UI test and you update/overwrite the action recording from Test Manager - how do you get the Coded UI test to use the new recording??
Comment posted by Sreeya on Monday, June 3, 2013 3:11 AM
I have created CUIT from existing test case recording, now that the requirement has changed. I want to update test case. How should i make those changes refelct in the corresponding CUIT.

Please help.
Comment posted by Gouri Sohoni on Monday, June 3, 2013 3:24 AM
Hi Sreeya,

You will have to re-reord the methods where there is change or change the code as per your requirement manually
Comment posted by Matt on Tuesday, September 3, 2013 12:37 PM
I don't hear any audio for the videos on this site (http://www.ssgsonline.com/AutoTesting.aspx ).

Thanks
Comment posted by Gouri Sohoni on Tuesday, September 3, 2013 11:54 PM
Hi Matt,

There is only video, no audio for the .wmv files

Gouri
Comment posted by Rohit on Tuesday, May 20, 2014 2:15 AM
HI Gouri,

Can I automate Telerik grid controls usinf CUIT?

Thanks,
Rohit
Comment posted by Gouri Sohoni on Wednesday, May 21, 2014 11:45 PM
Hi Rohit,
This is a list of configurations and platforms supported by CUIT
http://msdn.microsoft.com/en-us/library/dd380742.aspx

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