Unbale to identity WinForm ListView subitems in Coded UI test VSTS 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 used the http开发者_如何学JAVA://blogs.msdn.com/b/gautamg/archive/2010/02/19/useful-set-of-utility-functions-for-coded-ui-test.aspx?CommentPosted=true#commentmessage
WinListItem listItem = new WinListItem(control);
string[] strSubItems = WinExtensions.GetColumnValues(listItem);
In the above statement 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 suggest any other alternative ?.
I usually use smth like that:
WinList list;
UITestControlCollection columns = websitesList.Columns; // Get Columns names
// Get values
foreach (WinControl item in list.Items)
{
WinListItem listItem = new WinListItem(item);
string[] subItems = WinExtensions.GetColumnValues(listItem); // So you get value = subitem[i] in column[i]
}
精彩评论