1

数日前、 Windows アプリケーション(フレームワーク 2.0)の自動化された UI テスト ケースを作成するという要件を受け取りました。

テスト UI フレームワークとしてWhiteを使用することにしました。White フレームワークを使用して 3 つのレコードを表示しているDataGridコントロール (注: これは DataGridView ではありません) が見つからないように見えることを除いて、すべてがうまく機能します。

VisualUIAVerifyアプリケーションを使用して、実際に DataGrid がフォーム上にあり、それが UI アイテム タイプ「<strong> Table」であることを検証しました。コントロールに正しい AutomationId を使用していることは間違いありませんが、うまくいきません。

前に述べたように、DataGrid を除くフォーム上のすべてのコントロールを見つけることができます。私は何か間違ったことをしていますか?それとも、白は単に DataGrid をサポートしていないということですか。

どんな助けでも素晴らしいでしょう。ありがとう

ボビー

4

3 に答える 3

1

White から dataGrid にアクセスする必要があり、White が機能しない理由がわかりません (ソースがあり、時間があればそれを掘り下げます)。ただし、グリッド データを抽出する基本的なコードをいくつか書きました。配列。ありがたいことに、White フレームワークは AutomationElement へのアクセスを提供します。

以下のコードは最適化されていません... LinqPad で一緒にノックされました!

// The first few lines use White
var application = Application.Attach("AppName");
var window = application.GetWindow("The Window Title");
var datagrid = window.Get<White.Core.UIItems.TableItems.Table>("dataGridAutomationId").AutomationElement;

// Now it's using UI Automation
var headerLine = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Header));
var cacheRequest = new CacheRequest { AutomationElementMode = AutomationElementMode.Full, TreeScope = TreeScope.Children };
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(ValuePattern.Pattern);
cacheRequest.Push();
var gridLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
cacheRequest.Pop();

Console.WriteLine (headerLine.Count + " columns");
Console.WriteLine (gridLines.Count + " rows");

var gridData = new string[headerLine.Count, gridLines.Count];

var headerIndex = 0;
foreach (AutomationElement header in headerLine)
{
  gridData[headerIndex++, 0] = header.Current.Name;
}

var rowIndex = 1;
foreach (AutomationElement row in gridLines)
{
  foreach (AutomationElement col in row.CachedChildren)
  {
    // Marry up data with headers (for some reason the orders were different
    // when viewing in something like UISpy so this makes sure it's correct
    headerIndex = 0;
    for (headerIndex = 0; headerIndex < headerLine.Count; headerIndex++)
    {
      if (gridData[headerIndex, 0] == col.Cached.Name)
        break;
    }

    gridData[headerIndex, rowIndex] = (col.GetCachedPattern(ValuePattern.Pattern) as ValuePattern).Current.Value;
  }
  rowIndex++;
}
于 2013-02-01T11:00:50.120 に答える
1

最後に、DataGrid を使用するのではなく、DataGridView コントロールを使用するようにアプリケーションをアップグレードする必要がありました。White は DataGrid をサポートしていないように見えるため、これで問題が解決したようです。

于 2012-02-17T16:55:03.163 に答える