Coded UI Test (CUIT) - Convert Manual Test Case to Code using Visual Studio 2010
Posted by: Gouri Sohoni
in Category Visual Studio
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
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:
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:
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
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:
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.
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.
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.
Select the radio button for using existing recording. The query window will appear as follows:
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.
Step 8: Part of the code added in UIMap.Designer.cs looks as follows:
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.
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.
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.