Sdílet prostřednictvím


Coded UI Test

In the previous post, you saw how the Manual Testing has been made really easy with Camano. As I had mentioned, when you run through a manual test case for the first time, the Microsoft Test Runner (MTR) captures your UI actions as an “action log”. You have seen how this allows the tester to “fast forward” through her testing in subsequent runs, where MTR simply plays back the “action log”. This “action log” is also useful when it is time to turn a manual test into an automated test, which, for example, can be used as part of a build verification suite.

Let’s consider the case where you are testing the Windows Calculator and have a test case that checks some basic functionality of the application. You now want to automate the test, add validations, and run this regularly as part of a build cycle. Your goal is to ensure that there are no regressions in this part of the application. This is where the “Coded UI Test” feature of the VSTS 2010’s Test Edition comes into play.

Coded UI Test allows you to generate an automated test from a published test case in Team Foundation Server. You just point to the test case on a Team Foundation Server and code will be generated for the test. Magic!!! Not really. Visual Studio simply takes the action log  stored for the manual test and converts it into code. (Coded UI Test is a new test type in Visual Studio). I really like this simplicity in converting any manual test into an automated test!

As an example, the “action log” for the manual test case noted above may look like:

clip_image002[4]

When you convert this into a Coded UI Test, the actions noted above are translated into the following snippet of code.

clip_image004[4]

Now, in the manual testing case, the tester of course was able to verify in person that the above test case generates the result 9. Coded UI Tests allow to simply add such validations directly into the code. This is as simple as right-clicking the position in the code where you want to add the validation, bringing up the “UI Control Locator”, selecting the control and it’s property in the application that you want to add validation for, and letting the tool add the assertion. Here are some screen shots for the “UI Control Locator”, and the screen to select the control property to validate.

clip_image006[4]

 clip_image008[4]

You drag the crosshair of the control locator onto the result box of the application. Click on Add Control and Show Properties. Select the “DisplayText” property and hit OK. The following code gets generated for you.

clip_image010[4]

Presto! You have successfully created a Coded UI Test and you can now run it.

By the way, while in this case  we have generated the automation code from an existing manual test, you can also start from scratch and use a action recorder to record the actions you want translate into code. Here’s a screen shot of the action recorder

clip_image012[4]

Of course, you may not want to use any of the tools, but want to create Coded UI Test right at the API level.  For this, you can use the new Microsoft.VisualStudio.TestTools.UITesting API set to directly reference UI controls, perform actions, and validate properties.

It is also important to point out that code can be generated into any of the .Net languages. In the first version we will support code generation into C# and VB.Net. We hope this further helps break down the walls between developers and testers, where the automation engineers or developers can use the standard .Net languages for test automation code generation and there is no new scripting language to learn.

You will also be happy to know that, continuing with our theme of full integration of features across the life cycle, Coded UI Tests are fully integrated with Team Foundation Server (if you are using one).

  • You can publish the results of a Coded UI test run to Team Foundation Server. A bug may be created in Team Foundation Server from the results of a Coded UI Test run.
  • You can attach the Coded UI Test to a Test Case (see screenshot below). You can then run this automated test from Camano.
  • You can create a data driven test case sourcing its data from a test case on Team Foundation Server.

clip_image014[4]

This then completes a quick overview of the “Coded UI Test” feature. To reiterate again, you will use this feature when:

  • You want to add validations to your test
  • You want to create an automated test and run it as part of the build cycle
  • You want to customize your automated tests to improve its resilience

I am also including a link here for a step-by-step tutorial that walks you through the creation of a Coded UI Test - Tutorial on creating a Coded UI Test

Most of you are familiar with test automation and use it in some form or other in your projects. What you think of this new feature? Are there specific details you’d like me to elaborate in future posts? I am very interested in hearing from you – do leave a comment.

Comments

  • Anonymous
    March 14, 2009
    PingBack from http://www.clickandsolve.com/?p=23142
  • Anonymous
    March 14, 2009
    ブログ記事の紹介です。Visual Studio Team System 2010 の新機能である Coded UI Test についてわかりやすく紹介されている記事があります。 Amit Chatterjee's
  • Anonymous
    March 14, 2009
    Thank you for submitting this cool story - Trackback from DotNetShoutout
  • Anonymous
    March 16, 2009
    Thanks for providing this information Amit. We worked with this in the CTP and it shows great promise :) Can you please go through the running of tests against a selected data source. It is not functional in the CTP so we are curious to see where this is planned to go :)Bob Hanson
  • Anonymous
    March 18, 2009
    Hi Bob - we do support the running of a Coded UI test against a data source. Mathew Aniyan, talks about this in his blog post - http://blogs.msdn.com/mathew_aniyan/archive/2009/03/17/data-driving-coded-ui-tests.aspx. This post shows an example of data driving through a CSV file, but we support database sources as well.
  • Anonymous
    March 19, 2009
    Steve Lange on I told you it was coming!  "Team System Big event" The Public Sector DPE
  • Anonymous
    March 20, 2009
    Hello,    1) Can the Team Test system be used to test legacy(already existing) VB6 code?    2) Does Team Test have a way to simulate manipulating a legacy VB6 GUI, e.g. filling in dialog boxes, push GUI buttons, etc?Regards, Vasili
  • Anonymous
    March 24, 2009
    Hello Vasili - thank you for your question. For the VS 2010 release we will validate the GUI testing feature (record and playback) for Web, WinForms, and WPF platforms. However, the technology should work fine for VB6 as well - do give it a shot with our CTP bits. Likewise you will be able to generate a CodedUI test for VB6 applications as well - the generated code though will be in VB.Net or C# languages.
  • Anonymous
    March 24, 2009
    Hi Amit,   Thanks for your generous answer. What is CTP bits? Is it possible to get a pre-release of 2010 to try out the Team Test UI functionality?Very kind regards, Vasili
  • Anonymous
    March 24, 2009
    Hi Vasili - CTP stands for "Community Technology Preview". You can down load the last CTP bits for VS 2010 at - https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=9790
  • Anonymous
    March 24, 2009
    Thank you, Amit!Regards, Vasili
  • Anonymous
    April 25, 2009
    Hi Amit,Thanks for the intresting article.I'm working for a few years on automation of web based application with HP (former Mercury) QTP.I was wondering how well the "UI Control Locator" know to identify a dynamically generated UI element in HTML?Thanks,Eran
  • Anonymous
    May 18, 2009
    Hi Amit,  How are you?  When will Team Test 2010 be available for alpha? for beta? for release?Kind regards,Vasili
  • Anonymous
    May 19, 2009
    I am very excited proud and proud to introduce the new testing features you’ll find in dev10. In addition
  • Anonymous
    June 09, 2009
    Hello Amit,Does to CodedUI test work for infragistics controls?ThanksTom
  • Anonymous
    August 07, 2009
    Can I generate a load test using the Coded UI Test ?
  • Anonymous
    October 12, 2009
    Is it possible to customize the error messages that display in the Test Results? Is it possible to add log messages that indicate test steps?
  • Anonymous
    October 16, 2009
    The comment has been removed
  • Anonymous
    October 26, 2009
    coded ui testing not capturing the popup and the sub menus of the ui
  • Anonymous
    October 30, 2009
    In Working with Coded UI Tests, how would you manipulate the values of cookies?  We can do this with the current API we leverage for functional testing but haven't found a way to do so with the Coded UI framework.  Similarly, the current api we use exposes and http proxy such that in a test method, we can run blended tests at the UI or protocol (http) levels.  Is this possible with coded UI tests?
  • Anonymous
    November 15, 2009
    I like this post very much. Very informative and easy hands on for newbies like me. In addition I have seen significant changes in Beta 1 and Beta 2 code, do you have any plans to republish this post with Beta 2 changes?
  • Anonymous
    January 28, 2010
    how to use multiple CSV files for a single TESTMETHOD
  • Anonymous
    April 15, 2010
    Can any one explain the pros and cons of Coded UI and QTP
  • Anonymous
    June 01, 2010
    The comment has been removed
  • Anonymous
    June 01, 2010
    The comment has been removed
  • Anonymous
    September 02, 2010
    hi Amit, This is keshav .as i am new to coded ui testing i am not aware of how to start with could u please give some linksregarding the features o CUI .earlier i worked with QTP will it help in coded ui test.expecting reply soon.
  • Anonymous
    September 06, 2010
    Hi,I had a list of issues could you please aresolve it.Please find the link Belowspreadsheets.google.com/ccc
  • Anonymous
    September 06, 2010
    Does CUI supports Descriptive programming ? can any one please give some links in simple examples.please have a glanca on below linkspreadsheets.google.com/ccc
  • Anonymous
    September 23, 2010
    Hi All,I have visual studio 2010 installed but i am not able to see the coded UI automation in that.Please help.Thanks,Vaidy
  • Anonymous
    October 12, 2010
    Nop. Infragistics controls doesn't allow to acces to their field
  • Anonymous
    April 04, 2011
    Hi Amit,really good page on codedUI. Do you know if I can use this tool for automation test related with word/excel addins? Word does not expose the ID's of the control in the addin windows? So is there any work around to achieve this through codedUI?
  • Anonymous
    December 25, 2013
    hi amithow do I add a column inside the excel file to the textbox ?.
  • Anonymous
    April 04, 2014
    I am blogging about hand-coded CUIT over at burdettelamar.wordpress.com.  My post on DRY page objects is here:  burdettelamar.wordpress.com/.../keep-your-page-objects-dry