Speed up table readout in codedUI

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.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development, Test and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.