2012-01-31 13 views
5

Winformアプリケーションでグリッド(ComponentOneのFlexGrid)があり、セルの列インデックスとその値を考慮して、そのグリッド内のセルを検索しようとしています。CodedUI:セルの検索が遅いのはなぜですか?

グリッドをループしてそのセルを見つけるために、以下の拡張メソッドを記述しました。

私は6列と64行を持つグリッド上でそのメソッドをテストしています。私のコードが(最後の行にあった)正しいセルを見つけるのに10分かかりました

私のアルゴリズムをスピードアップする方法はありますか?

注:私もTOPLEVELWINDOWにPlayBack.PlayBackSetting.SmartMatchOptionを設定しようとしましたが、何も変更していないようだ...

ありがとう!

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue) 
    { 

     int count = table.GetChildren().Count; 
     for (int rowIndex = 0; rowIndex < count; rowIndex++) 
     { 
      WinRow row = new WinRow(table); 
      WinCell cell = new WinCell(row); 
      row.SearchProperties.Add(WinRow.PropertyNames.RowIndex, rowIndex.ToString()); 
      cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 

      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      if (cell.Exists) 
       return cell; 
     } 

     return new WinCell(); 
    } 

編集

私は(例えば。私はもうwinrowを使用しない)以下のようになり、私の方法を変更し、これは速く3倍の周りのようです。しかし、3行6列の表のセルを見つけるのにまだ7秒かかるので、まだかなり遅いです...

私はこの回答に後で受け入れられるとマークして、他の人に推薦するようにしますより良い何か

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 
     Playback.PlaybackSettings.SmartMatchOptions = Microsoft.VisualStudio.TestTools.UITest.Extension.SmartMatchOptions.None; 
     int count = table.GetChildren().Count; 
     for (int rowIndex = 0; rowIndex < count; rowIndex++) 
     { 
      WinCell cell = new WinCell(table); 

      cell.SearchProperties.Add(WinRow.PropertyNames.RowIndex, rowIndex.ToString()); 
      cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 


      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      if (cell.Exists) 
       return cell; 
     } 

     return new WinCell(); 
    } 

編集#2: 私はAndriiの提案@ごとにFindMatchingControlsを使用して試してみた、と私はほとんどそこだし、セルの列インデックス(c.ColumnIndex)以下のコードでことを除いて、間違った値を持つ..

public static WinCell FindCellByColumnAndValue2(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 

     WinRow row = new WinRow(table); 
     //Filter rows containing the wanted value 
     row.SearchProperties.Add(new PropertyExpression(WinRow.PropertyNames.Value, strCellValue, PropertyExpressionOperator.Contains)); 
     var rows = row.FindMatchingControls(); 
     foreach (var r in rows) 
     { 
      WinCell cell = new WinCell(r); 
      cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 
      //Filter cells with the wanted value in the current row 
      var controls = cell.FindMatchingControls(); 
      foreach (var ctl in controls) 
      { 
       var c = ctl as WinCell; 
       if (c.ColumnIndex == colIndex)//ERROR: The only cell in my table with the correct value returns a column index of 2, instead of 0 (being in the first cell) 
        return c; 
      } 
     } 
     return new WinCell(); 
    } 
+0

ベンダーに問い合わせてください。 – leppie

+0

MSDNフォーラムの[UI Automation Testing](http://social.msdn.microsoft.com/Forums/da/vsautotest/threads)セクションでは、通常、Coded UIに関する質問に対して非常に広範な回答が提供されることに同意します。 –

+0

@leppie:yep、フォーラムにメッセージを投稿しました。私はちょうど答えを待っています。 – David

答えて

6

私は子供のコントロールを介して直接ループを実行することをお勧めします - 私の経験によると、コード化されたUIの複雑な検索目当てのコントロールを検索することはしばしば遅くなります。

編集:

テーブルの子供をカウントした行をループ削除する方がよいパフォーマンスを向上させることができます。テーブルのフィールドは、それが表に子コントロールをカウントするための時間を節約するテーブルで直接検索されます場合は

public static WinCell FindCellByColumnAndValue(this WinTable table, int colIndex, string strCellValue, bool searchHeader = false) 
    { 
     Playback.PlaybackSettings.SmartMatchOptions = Microsoft.VisualStudio.TestTools.UITest.Extension.SmartMatchOptions.None; 

     WinCell cell = new WinCell(table); 
     cell.SearchProperties.Add(WinCell.PropertyNames.ColumnIndex, colIndex.ToString()); 
     cell.SearchProperties.Add(WinCell.PropertyNames.Value, strCellValue); 

     UITestControlCollection foundControls = cell.FindMatchingControls(); 
     if (foundControls.Count > 0) 
     { 
      cell = foundControls.List[0]; 
     } 
     else 
     { 
      cell = null; 
     } 

     return cell; 
    } 

:あなたは、次のようにFindMatchingControls方法を、使用することができます行番号なしのコントロールを見つけたときにも例外を避けるために。また、forループなしで検索すると、一致しない行番号の繰り返しごとにフィールドを検索する時間が節約されます。

行番号は、エクステンション内の利用可能なすべての値を通じて繰り返されます。長期的には必須の検索基準ではありません。同時に、行番号の値を繰り返し実行するごとに、追加の制御検索要求が呼び出され、結果的にメソッドの実行時間にグリッドの行数が掛けられます。

+0

あなたがtable.GetChildren()を使用していると仮定すると、 ( – David

+1

)私はすでにそれを試していましたが、次のエラーが発生しています System.ArgumentException:コントロールの検索コンテナとして指定された行がありません。 'ColumnIndex '、コンテナ要素としてrowを指定するか、セルの検索プロパティに' RowIndex 'を追加する必要があります。 パラメータ名:SearchProperties そのため、私はまだ行を使用しています。 – David

+0

@David指定された行番号なし? –

関連する問題