New to Telerik Test Studio Dev Edition? Start a free 30-day trial
Verify Sort Order in a Silverlight DataGrid
I would like to sort a column in a Silverlight DataGrid and verify the content is in the correct order.
Solution
This is possible with a coded solution. The example below is against a Silverlight toolkit sample.
After navigating there, click DataGrid in the left-hand menu. Then click the FirstName column header to sort that column. Finally, add a coded step:
C#
//Get the data grid.
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
DataGrid grid = app.Find.ByAutomationId<DataGrid>("dataGrid");
int r = grid.Rows.Count;
List<string> list = new List<string>();
//Place the TextBlock content of the FirstName cell from each row into the string list.
for (int i = 0; i < r; i++)
{
DataGridRow row = grid.Rows[i];
DataGridCell cell = row.Cells[2];
list.Add(cell.TextBlockContent);
Log.WriteLine(cell.TextBlockContent);
}
//Assert each string in the list is greater than the string before it.
for (int j = 0; j < list.Count; j++)
{
if (j+1 == list.Count)
{
break;
}
else
{
Assert.IsTrue(list[j+1].CompareTo(list[j]) >= 0);
}
}