Share via


Useful set of utility functions for Coded UI Test!

We have collected various internal and external feedback and built up a library of utility functions for Coded UI Test for various Web\Win\WPF controls.  These APIs will work on VS2010 RC (30128.01) or later only (if you have not moved, good time to do it now). 

The table of all the APIs with example usage is below.  Some important ones are –

  • Find column names and column values for List View controls.
  • Get content of controls like Data Grid or List and validate it in one shot.
  • Get tool tip text of control
  • Find broken links on the page

Refer attachment, it contains 3 files –

  • The UITestingUtilities.dll (library assembly)
  • The UITestingUtilities.xml (the document file for VS) and
  • The UITestingUtilities.mht (the help file)

To use, unzip the files on the disk and add reference to the dll.  As you use these APIs, do send me your feedback, bugs and anything else missing.  Based on the feedback, we will absorb some of these APIs into the product itself.

Note that this is not a product binary and hence not supported by us.  However, if you do find an issue, please report to me and I will do my best to get the fix out. 

UITestingUtilitiesOct132010.zip

Comments

  • Anonymous
    March 31, 2010
    Thanks for putting these utilities together for all of us out here Gautam. I would like to use your method "FindFirstCellWithValue" but it appears the code only looks at TD cells and does not include TH cells. Could you either post the code for this method so we can modify it or could you modify the function to look at both TD and TH cells? Thanks for any help you can provide.

  • Anonymous
    March 31, 2010
    Thanks Steve for using Coded UI Test and this utility. Something like this should do the trick -        /// <summary>        /// Finds the first header cell with the given value.        /// </summary>        /// <param name="table">The HtmlTable object.</param>        /// <param name="value">The value to find for.</param>        /// <returns>The first header cell with the value.</returns>        /// <remarks>        /// Example - Find first header cell with value 'Coded UI Test'.        ///     HtmlHeaderCell cell = myTable.FindFirstHeaderCellWithValue("Coded UI Test");        /// </remarks>        public static HtmlHeaderCell FindFirstHeaderCellWithValue(this HtmlTable table, string value)        {            if (table == null) throw new ArgumentNullException("table");            // Set properties on the cell and return.            HtmlHeaderCell cell = new HtmlHeaderCell(table);            cell.SearchProperties[HtmlHeaderCell.PropertyNames.InnerText] = value;            cell.Find();            return cell;        } The actual code is same as above - just that it uses HtmlCell instead of HtmlHeaderCell. Thanks.

  • Anonymous
    June 14, 2010
    Can you provide a code example that shows, how one can access the text of a certain cell of a ListView?

  • Anonymous
    June 17, 2010
    This is really helpful.Thanks Gautam.

  • Anonymous
    June 22, 2010
    Hi Gautam, I'm using some functions from your testing utilities in my tests, I have added the .dll to the root of my project folder and have added the dll as a reference to my project and checked the project back into TFS. This is all fine, but when I get the latest version of my solution (and overwrite all files even if latest version matches local version), I am receiving an error after building regarding the .dll, I have to remove the reference and then re-add the reference to my project again to rectify it. Any ideas on why this is happening? For some reason the solution builds fine in debug mode.

  • Anonymous
    July 12, 2010
    Sorry for late reply.  For some reason, my blog settings got messed up and I had trouble login in.  In general, the Coded UI Test forum (social.msdn.microsoft.com/.../threads) is better place to post your questions as that is monitored by many folks & you will get faster response. @Naresh - Thanks. @Mairead - No idea.  If you could, post your solution at the above forum and someone might be able to help. @stgn - You can use WinList.GetColumnValues() to get the cell values.  This returns an string array which is the value of all the cells. Thanks, Gautam

  • Anonymous
    August 19, 2010
    There is no metnod GetColumnValues()  in WinList Class .Can you please give an example of how to retreive ListView Column value

  • Anonymous
    August 19, 2010
    @vijay - In the attached dll, you will find three extension methods -  1. WinList.GetColumnNames() - Use this to get the names of the columns of the WinList.  2. WinListItem.GetColumnValues() - Use this to get a row of data i.e. all the cells of given list view item.  3. WinList.GetContent() - Use this to get the entire table of data as one dimensional array.

  • Anonymous
    August 22, 2010
    in related to my previos query when i use WinExtensions.GetColumnValues is gives error Invalid IO Operation stating "The control passed is not a list view item control.  This operation is valid only for list view item control."            foreach (WinControl control in wkList.Items)            {                 WinListItem listItem = new WinListItem(control);                string[] strSubItems = WinExtensions.GetColumnValues(listItem);            }

  • Anonymous
    August 22, 2010
    Please put a post on social.msdn.microsoft.com/.../threads with proper details for someone to follow up on this. Thanks.

  • Anonymous
    August 22, 2010
    This is my window application code for listview :-          // Create three items and three sets of subitems for each item.            ListViewItem item1 = new ListViewItem("item1", 0);            item1.SubItems.Add("1");            item1.SubItems.Add("2");            item1.SubItems.Add("3");            ListViewItem item2 = new ListViewItem("item2", 1);            item2.SubItems.Add("4");            item2.SubItems.Add("5");            item2.SubItems.Add("6");            ListViewItem item3 = new ListViewItem("item3", 0);            // Place a check mark next to the item.            item3.Checked = true;            item3.SubItems.Add("7");            item3.SubItems.Add("8");            item3.SubItems.Add("9");            // Create columns for the items and subitems.            // Width of -2 indicates auto-size.            listView1.Columns.Add("Item Column", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Column 2", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Column 3", 100, HorizontalAlignment.Left);            listView1.Columns.Add("Column 4", 100, HorizontalAlignment.Center);            //Add the items to the ListView.            listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 }); Then i add the lisview control in Coded UI test  :- In the coded UI test i used below code WinList wkList = this.UIForm1Window.UIListView1Window.UIListView1List;            string[] strVal = CommonExtensions.GetValuesOfControls(wkList.Items);            foreach(WinControl control in this.UIForm1Window.UIListView1Window.UIListView1List.Items)            {                int count = control.GetChildren().Count;                object objVal = CommonExtensions.GetValue(control);                WinListItem lstItem = (WinListItem)objVal;            } in the "strVal " variable gives only values of first column not the subitems. in add watch window i get below mentioned value:- strVal[0] = "item1" strVal[1] = "item2" strVal[2] = "item3" I have also tried WinListItem listItem = new WinListItem(control); string[] strSubItems = WinExtensions.GetColumnValues(listItem); But i am getting Invalid Io expection stating "The control passed is not a list view item control.  This operation is valid only for list view item control." Please can you give me code snippet to acces List View Subitems. Let me know if you require any more information. I have also posted the query in social.msdn.microsoft.com/.../threads

  • Anonymous
    September 05, 2010
    hi, can any one tell me how to get values from a html table as i am new to coded ui where to write code in designer or in .cs file.please give the code. i am confusing in writing the code whether in .cs or designer file.can u please give clear picture? thanks in advance

  • Anonymous
    September 06, 2010
    The comment has been removed

  • Anonymous
    September 10, 2010
    Hi Gautham, I am working with coded ui newly. really  its features are good. i had a problem in when dragging cross hair on control its class name showing as html table. but  its id as DetailsGridview.my doubt is,what should i consider for as control type is it a grid or a html table.is there any difference?.and also i need to capture each cell data and compare with database.my table is just like given below.please click the link. if possible give some code. its urgent. thanks in advance spreadsheets.google.com/ccc

  • Anonymous
    September 12, 2010
    The comment has been removed

  • Anonymous
    September 23, 2010
    Hi Gautam...First off thanks for giving us this DLL..I am using those methods a lot.. Is it possible to get the souce code as well,since that might help us tackle similar situations in our scenarios...Thanks again...

  • Anonymous
    September 23, 2010
    Can we get the source code as well for this.It might really help us to write better automation code.

  • Anonymous
    September 23, 2010
    @Brooke and @Achin - Let me check on the formalities around this and get back.

  • Anonymous
    October 15, 2010
    Hi, I would like to add this dll file, and give it a try.  What is the directory path I should use? Thank you

  • Anonymous
    October 15, 2010
    The comment has been removed

  • Anonymous
    November 24, 2010
    Hey Gautam. I am interested in your fourth point. Identifying broken links. I am looking at running a script that can traverse all parent , child and grandchild etc links in sharepoint application and get me the list of broken links. Do you have any readymade code for the same? since we are from the testing community, we have limited coding exposure. Thanks.

  • Anonymous
    November 24, 2010
    Hi. Do u have a code for checking the sharepoint site for broken links by traversing parent/children/grandchildren links and so on. A complete test for broken links. Kindly help. Thanks.

  • Anonymous
    November 25, 2010
    @Sharepoint User - Please check various overloads of IsBrokenLink function in the attached library.  For example, using Coded UI Test, you can get an HtmlDocument and then call FindAllBrokenLinks() function on it.  The attached zip contains help file. Thanks.

  • Anonymous
    March 02, 2011
    how can i get all the rows of a wpf table

  • Anonymous
    March 06, 2011
    There is WpfTable.Rows property!

  • Anonymous
    March 10, 2011
    Hi Gautam! I'm having a problem with the UITesting Utilities method GetContent(). While debugging it's bringing the same results as GetColumnNames(). Is this a known issue? Thanks!

  • Anonymous
    March 17, 2011
    Is this custom control or standard Windows Forms Data Grid?  I have not tested this for custom controls.

  • Anonymous
    April 06, 2011
    Hi Gautam, While trying to use this dll, I added its reference in my project. But at runtime, when i try and access its methods it gives me following error : uIItemList.GetColumnNames() 'Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinList' does not contain a definition for 'GetColumnNames' and no extension method 'GetColumnNames' accepting a first argument of type 'Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinList' could be found (are you missing a using directive or an assembly reference?)     Can you suggest why is it not able to get the definition of methods and what else needs to be done to rectify this

  • Anonymous
    April 06, 2011
    @Tanmay - This means that the dll is not getting deployed properly.  Ensure "CopyLocal" property of this reference in VS is set to true.

  • Anonymous
    May 23, 2011
    The comment has been removed

  • Anonymous
    May 23, 2011
    There are some known limitations with ATL and MFC.  Please post at social.msdn.microsoft.com/.../threads and see if someone in the community can help you here. Thanks.

  • Anonymous
    August 03, 2011
    Hi..is there any property like Columns  for HtmlTable like for server side control, so that I can access a column by index. Can we add the methods or properties for Html controls that are similar to server controls? Thanks In Advance...

  • Anonymous
    August 08, 2011
    @Madhu - The Coded UI Test works on the Client UI and hence would work only on the client side objects.  Your server control will get transformed to appropriate HTML in client side and you have to figure that out & use appropriate API. Thanks.

  • Anonymous
    August 15, 2011
    I am working on an automation script for a .Net application. I would like to use this utilities file in order to get the value of each of the cells in a ListView (WinList). Can anyone please direct me on how to start with this utilities file?  --I've already made reference to the .dll file in my project. But how do I refer to its methods in the script code?

  • Anonymous
    August 16, 2011
    @Jusus - Refer the mht file in the zip for help.

  • Anonymous
    August 23, 2011
    Hi.. Thank you for your reply.  Can we compare strings in Coded UI test by using String methods. When I use string.equals() or String.compare(), even though strings are same it is not working. I need boolean as return value. Assert.AreEqual() returns void. Is there any api for that? I know there is A Test Api available. But I have not used it. Thanks...

  • Anonymous
    August 23, 2011
    Yes, you should be able to use String.Equals and String.Compare.  See if your strings are case-sensitive.  If so, you need to ask String.Equals to ignore case. Thanks.

  • Anonymous
    August 28, 2011
    Hi..Thankyou for your reply. The issue was resolved. I am not  getting HtmlProperties in intellisense to add in search properties. For example this.UIMapWorkgroup.UISelectUserMicrWindow.UISelectUserDocument.UIGvDataTable1.UIAdminHyperlink.SearchProperties.Add(HtmlProperties.).Do  i need to add any reference to a dll.   Thanks...

  • Anonymous
    September 04, 2011
    The HtmlProperties are string and won't come in Intellisense.

  • Anonymous
    September 25, 2011
    Sometimes, we can open a link through IE. But when we use IsBrokenLink to test it, it returns true. It's not always the case, the it sometimes happens. Is there some timeout mechanism for it ? Maybe it fails because the web performance is not very good ?

  • Anonymous
    September 25, 2011
    Yes, there is a default timeout (same as WebRequest.Timeout as mentioned at msdn.microsoft.com/.../system.net.webrequest.timeout.aspx).  To change the timeout, you can use overload of IsBrokenLink API and specify your own timeout.

  • Anonymous
    October 24, 2011
    Hi I'm farely new to coded ui test 2010. I am trying to use your utility to find a count for all the hyperlink with id =xxxxsample in my container, but when I add a reference to the UITestingUtilities it give me an error. Can you help me with this? Thanks a million

  • Anonymous
    October 24, 2011
    @angel - What is the error you are seeing?  Use the "Email Blog Author" link above to send me the error.

  • Anonymous
    October 26, 2011
    Hi Gautam, I am not able to run recorded content when the grid control having checkbox control.  what is the solution for this. Following is the error Another control is blocking the control. Please make the blocked control visible and retry the action. Additional Details: TechnologyName:  'MSAA' Name:  'row 1, column 0' ControlType:  'CheckBox' Thanks, Saiprasad Rao

  • Anonymous
    October 31, 2011
    @sai - The error indicates that there are two controls completely overlapping each other.  The control that you are trying to access is one that is below the other control and hence the failure. Beyond this it is difficult to sayfix the issue.  You should debug it yourself and if the problem is still not solve, try forum - social.msdn.microsoft.com/.../threads

  • Anonymous
    April 12, 2012
    The comment has been removed

  • Anonymous
    April 12, 2012
    Hi Kiran - Clearly there is some change in the new deployment that is causing this.  Based on the information above, it is difficult to say what is that. You need to debug this further yourself and if you need help, I suggest posting on the forums mentioned above with logs to see if anyone in community can help you. Thanks.

  • Anonymous
    June 05, 2012
    Hi Goutham, The dll is not working for me, getting empty values for SYSLISTVIEW32 winlist item, could you help me in this? While doing automation, i wtore the code as below, just passed the "lst" winlist with search properties, but i am getting empty values, unable to read the SYSLISTVIEW32 winlistitem value. string[] strVal = CommonExtensions.GetValuesOfControls(lst.Items);                foreach (WinControl control in lst.Items)                {                    int count = control.GetChildren().Count;                    object objVal = CommonExtensions.GetValue(control);                    WinListItem lstItem = (WinListItem)objVal;                }                foreach (WinControl control in lst.Items)                {                    WinListItem listItem = new WinListItem(control);                    string[] strSubItems = WinExtensions.GetColumnValues(listItem);                }                string[] ss = lst.GetColumnNames();                string[] colval = userlists.GetColumnValues(); i am getting the objects as below, <AndCondition Id="SearchCondition"> <PropertyCondition Name="ControlType">ListItem</PropertyCondition> <PropertyCondition Name="Instance">3</PropertyCondition> </AndCondition> <AndCondition Id="SearchCondition"> <PropertyCondition Name="ControlType">List</PropertyCondition> </AndCondition> Thank You, Sandeep

  • Anonymous
    June 05, 2012
    Thanks alot Gautam... this has saved my life :-)

  • Anonymous
    June 06, 2012
    @sandeep - it is difficult to comment much here.  You will have to debug it yourself.

  • Anonymous
    June 06, 2012
    Hi Gautham, Thanks for the quick reply, I have already debug the code,  it is giving only the grid column header names only. first i am working on Windows Applications, Coded UI is able to record the buttons, text boxes and all. But coming to the Grid which is having "SYSLISTVIEW32" - classname, the code ui is unable to get the Search Properties & Filter Properties for that control. it is just showing me just ControlType = ListItem, Instance=3 in the object repository. <UIObject ControlType="ListItem" Id="UIItemListItem" FriendlyName="" SpecialControlType="None">                  <TechnologyName>MSAA</TechnologyName>                  <WindowTitles>                    <WindowTitle>TITLE XXXXXXX</WindowTitle>                  </WindowTitles>                  <AndCondition Id="SearchCondition">                    <PropertyCondition Name="ControlType">ListItem</PropertyCondition>                    <PropertyCondition Name="Instance">3</PropertyCondition>                  </AndCondition>                  <SupportLevel>0</SupportLevel>                  <Descendants />                </UIObject> could you hellp me on this. Thank You, Sandeep.

  • Anonymous
    June 19, 2012
    when using the Coded UI Testing , it couldn't read the name of controls in the splash screen it displayed as 'Unknown control ' So , is there any solution for this issue please I need the reply ASAP thanks all

  • Anonymous
    July 01, 2012
    Hi Gautam,    How do I reference these utilities in my project to be able to use them?

  • Anonymous
    July 08, 2012
    Gautam, I see an error message "System.InvalidOperationException: The control passed is not a list view control.  This operation is valid only for list view control" when I do the following            WinList list = new WinList(myWindow);            string[] headers = list.GetColumnNames(); However if I change my code as follows it works perfectly fine.            WinList list = new WinList(myWindow);            WinListItem listItem = new WinListItem(list);            WinList listView = listItem.GetParent() as WinList;            string[] headers = listView.GetColumnNames(); This could be a possible bug. Or is it supposed to behave that way? Thanks for the DLL, hope this is included in the next official release. -Madhu.

  • Anonymous
    July 08, 2012
    @Sandeep - I still cannot figure much here.  Please post on forums.

  • Anonymous
    July 08, 2012
    @Quality Engineer S.S - It is difficult to say what could be wrong.  The unknown error typically comes when there is poor accessibility support.  Please try coded UI test forum.

  • Anonymous
    July 08, 2012
    @Nitisha - In VS, you can use Add Reference to add the reference to the binary.

  • Anonymous
    July 08, 2012
    @Madhu - Yes, part of these is being moved into the product.  I am not sure what the issue here is - suggest you contact someone via forum.

  • Anonymous
    September 02, 2012
    The above mentioned Zip file is not available for download. Its been removed. Please suggest where can I get the downloadable Zip ?

  • Anonymous
    September 11, 2012
    The comment has been removed

  • Anonymous
    October 05, 2012
    I have a HtmlTable containing 11 columns and Rows( dynamic number). i need to get the value of  a cell in column 5  depending on value of column 6 of the same row. how do i first find the row in which Search value is reciding in column 6 and then pick up the value in the cell of same row of column 5. pl. let me know.

  • Anonymous
    October 18, 2012
    I'm trying to use this utility but I'm getting build errors so I'm missing something.  I've added the refence to the .dll as mentioned here but I'm getting the following build error : "Error 1 The type 'mshtml.IHTMLCurrentStyle' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and Error 2 The type or namespace name 'UITestingUtilities' could not be found (are you missing a using directive or an assembly reference?)

  • Anonymous
    October 29, 2012
    You can easily get cell by row and column index without using this library.

  • Anonymous
    October 29, 2012
    For error 1, add a reference to the Microsoft.mshtml assembly.  Coded UI Test also adds this but probably you may have deleted it. For error 2, ensure UITestingUtilities is deployed in the same folder as the test binary.  One easy way to do this is to do F4 on the reference and then in properties window of VS, set Copy Local to True.