We still use codedUI in our releases for testing. Migration to selenium is added to the backlog. Until it is added to the sprint we are working with codedUI and we must maintain it. We noticed the table readout was very slow and that is something we do a lot. Time to speed things up.
By adding trace writelines and the stopwatch (both in System.Diagnostics) we pinpointed the bottleneck in the iteration for getting the data from the cells. Looking at the code we noticed that the slow part used the index. The foreach for getting the fields was fast. So we rewrote the index to a foreach:
public DataTable GetDataTableWaarde() {
var control = FindHtmlTable(); // search with the id
var datatable = new DataTable();
// 1. header contains the fields > add columns
var headerRow = control.GetRow(0);
foreach(HtmlHeaderCell header in headerRow.GetChildren()) {
datatable.Columns.Add(header.InnerText);
}
// 2. rows contain the data > add rows
foreach(HtmlRow row in control.Rows.Skip(1)) {
var newRow = datatable.NewRow();
try {
// this is slow:
//for (int i = 0; i < datatable.Columns.Count; i++) {
// newRow[i] = row.GetCell(i).InnerText;
//}
// this is fast:
foreach(HtmlCell cell in row.Cells) {
newRow[cell.ColumnIndex] = cell.InnerText;
}
datatable.Rows.Add(newRow);
} catch (Exception) {
// handle exception
}
}
return datatable;
}
After this change the table readout went from 40 seconds down to 4 seconds (including the validation) The total test time went down from 56 minutes to 26 minutes by changing two lines of code and some kaizen blitzen.