Very Very slow control search even with a small DataGridView

Mar 11, 2009 at 6:03 AM
Edited Mar 11, 2009 at 6:16 AM

Hi All,

First of all congratulations to Vivek and other contributors for developing a framework like White to make automation testing very simple and effective. I am a new user of it and started on it only a month ago.

I faced a serious issue. It seems that white takes an unbearable amount of time to search any control on a winform (.net 2.0) that has DataGridView with say just 200 cells (100 rows X 2 columns). To confirm the issue and to make sure that this is not due to something specific in my project, I created a simple independent winform with just a text box and a datagridview control on it. The datagridview control has 200

DataGridViewTextBoxCells (100 rowsX 2 columns). Now I wrote a white test to enter some text in the textbox and to click a cell in the datagridview. And to my grief white takes around 2 minutes to find the textbox and around 6 minutes to double click a cell in the datagridview :(. I tried the Poistion Based search method too, but it just helps to find the textbox fast from the next time but it doesn't help at all about the datagridview cells search.

 

Here's my code for the form:

 

Form1.Designer.cs

namespace

GridTest 
{
partial class Form1 

 

 

/// <summary>
///
Required designer variable.
/// </summary>

 

 

private System.ComponentModel.IContainer components = null;

 

 

 

/// <summary>

 

 

///

Clean up any resources being used.

 

 

/// </summary>

 

 /// <param name=

"disposing">true if managed resources should be disposed; otherwise, false.</param>

 

 

protected override void Dispose(bool disposing
{

if (disposing && (components != null))

 

 

{

 

components.Dispose();

base.Dispose(disposing); }

 

 

 

#region Windows Form Designer generated code

 

 

/// <summary>

 

 ///

Required method for Designer support - do not modify

 

 

/// the contents of this method with the code editor.

 

 

/// </summary>

 

 

private void InitializeComponent()

 

 {

 

this.textBox1 = new System.Windows.Forms.TextBox();

 

 

this.dataGridView1 = new System.Windows.Forms.DataGridView();

 

 ((

System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();

 

 

this.SuspendLayout();

 

 

//

 

 // textBox1

//

 

this.textBox1.Location = new System.Drawing.Point(77, 12);

 

 

this.textBox1.Name = "textBox1";

 

 

this.textBox1.Size = new System.Drawing.Size(100, 20);

 

 

this.textBox1.TabIndex = 0;

 

 

//

 

// dataGridView1

//

 

this.dataGridView1.AllowUserToAddRows = false;

 

 

this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

 

 

this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;

 

 

this.dataGridView1.Location = new System.Drawing.Point(30, 62);

 

 

this.dataGridView1.Name = "dataGridView1";

 

 

this.dataGridView1.Size = new System.Drawing.Size(754, 484);

 

 

this.dataGridView1.TabIndex = 1;

 

 

this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1CellDoubleClick);

 

 

//

 

// Form1

//  

 

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

 

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

 

 

this.ClientSize = new System.Drawing.Size(829, 589);

 

 

this.Controls.Add(this.dataGridView1);

 

 

this.Controls.Add(this.textBox1);

 

 

this.Name = "Form1";

 

 

this.Text = "Form1";

 

 

this.Load += new System.EventHandler(this.Form1_Load);

 

 ((

System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();

 

 

this.ResumeLayout(false);

 

 

this.PerformLayout();

 

 }

 

#endregion

 

 

private System.Windows.Forms.TextBox textBox1;

 

 

private System.Windows.Forms.DataGridView dataGridView1;

 

 }
}

 

Form1.cs

using

System;

 

 

using System.Collections.Generic;

 

 

using System.ComponentModel;

 

 

using System.Data;

 

 

using System.Drawing;

 

 

using System.Text;

 

 

using System.Windows.Forms;

 

 

namespace GridTest 

 

 

public partial class Form1 : Form  

 

 

{  

 

 

public Form1() 
 { 

 

 

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e

 

 

dataGridView1.Columns.Add(new DataGridViewTextBoxColumn());  

 

 

dataGridView1.Columns.Add(new DataGridViewTextBoxColumn());

 

for (int i = 0; i < 200; i++)

 

 {

 

DataGridViewRow dr = new DataGridViewRow();

 

 

DataGridViewCell dc1 = new DataGridViewTextBoxCell();

 

 

dc1.Value = "Row" + i.ToString();

 

 

dr.Cells.Add(dc1);

 

 

DataGridViewCell dc2 = new DataGridViewTextBoxCell();

 

 

dc2.Value = "Row Value : " + i.ToString();

 

 

dr.Cells.Add(dc2);

 

 

dataGridView1.Rows.Add(dr);

 

 }

}

 

 

void DataGridView1CellDoubleClick(object sender, DataGridViewCellEventArgs e)

 

dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value="Cell Double Cliked";  

}

}

}

 

Here's the white test code:

 

[Test]  

 

 

public void Form1GridTest()  

{  

 

//Window _form1window = _app.GetWindow("Form1", InitializeOption.NoCache.AndIdentifiedBy("MyGrid") );

 

Window _form1window = _app.GetWindow("Form1", InitializeOption.NoCache);

 

 

//test if the object is null

 

 

Assert.IsNotNull(_form1window,"window not found");

 

 

System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

 

 

SearchCriteria searchCriteria = SearchCriteria.ByAutomationId("textBox1");

 

 

TextBox txtUser = _form1window.Get<TextBox>(searchCriteria);

 

 

Assert.IsNotNull(txtUser,"text box not found");

 

 

txtUser.Text = "This is some text!!!";

 

 

searchCriteria = SearchCriteria.ByAutomationId("dataGridView1");

 

 

AutomationElement dgPartSearchResult = _form1window.GetElement (searchCriteria);

 

 

Assert.IsNotNull(dgPartSearchResult,"dataGridView1 not found");

 

 

Table tbldgPartSearchResult = new Table(dgPartSearchResult,_form1window.ActionListener);

 

 

Assert.IsNotNull(tbldgPartSearchResult,"tbldgPartSearchResult not found");

 

 

//tbldgPartSearchResult.LogStructure();

 

 

tbldgPartSearchResult.Rows[2].Cells[0].DoubleClick();

 

 

//_app.ApplicationSession.Save();

 

 

System.Windows.Forms.MessageBox.Show((sw.ElapsedMilliseconds/1000).ToString());

 

 }

 

It takes about 8 minutes to run this test.

Please see if you can fix this as our whole project has forms with grids like this.

Please get back to me on this as early as you can.

Any quick help will be greatly appreciated
Mar 11, 2009 at 3:34 PM

Hi,

 

I’m also facing the same problem.

 

But improved the performance by the following workaround in the TableRowFactory class

 

        private List<AutomationElement> GetRowElements()

        {

            #region CUSTOM_CODE

 

            //

            // Following changes are done to increase the performance . . .

            //

 

            //AutomationElementCollection descendants = automationElementFinder.Descendants(AutomationSearchCondition.ByControlType(ControlType.Custom));

            //BricksCollection<AutomationElement> automationElements = new BricksCollection<AutomationElement>(descendants);

 

            //return automationElements.FindAll(rowPredicate);

 

            List<AutomationElement> rowElements = new List<AutomationElement>();

            AutomationElementCollection rowElementsAE = automationElementFinder.AutomationElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));

 

            foreach (AutomationElement element in rowElementsAE)

            {
                // The following is used in the constructor when defining the row predicate . . .

                if (element.Current.Name.ToLower().StartsWith("row ".ToLower()) && element.Current.Name.Split(' ').Length == 2)

                {

                    rowElements.Add(element);

                }

            }

 

            #endregion

 

            return rowElements;

        }

 

Please try this . . .

 

Thanks & Regards,

Kannan

Mar 12, 2009 at 6:01 AM
Hi Kannan,
                 I tried it but it didn't helped in any mannar :(. Anywayt but thanks a million for your reply :). Hard luck for me that it didn't helped :)

Regards,
Ram