1

几天前,我收到了为我的Windows 应用程序(框架 2.0)创建自动化 UI 测试用例的要求。

我决定使用White作为测试 UI 框架。现在一切正常,除了我似乎找不到使用 White 框架显示 3 条记录的DataGrid控件(注意:这不是 DataGridView)

我已经使用VisualUIAVerify应用程序来验证 DataGrid 确实在表单上,​​并且它是 UI 项类型“<strong> Table ”,并且我定义地使用正确的 AutomationId 作为控件,但仍然没有运气。

如前所述,我可以在表单上找到除 DataGrid 之外的所有控件。难道我做错了什么 ?还是说白根本不支持DataGrid。

任何帮助都会很棒。谢谢

鲍比

4

3 回答 3

1

最后不得不升级我的应用程序以使用 DataGridView 控件而不是使用 DataGrid。这似乎解决了问题,因为 White 似乎不支持 DataGrid

于 2012-02-17T16:55:03.163 回答
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 回答
0

我不确定您是否遇到与我完全相同的问题,因为我没有足够的代码,但是我在 WPF 应用程序中遇到了同样的问题,我试图访问实际上写为的 DataGrid一个存在于 ListView 中的 GridView 项。

我的问题的解决方案是告诉 White 获取 ListView 项(即 TestStack.White.UIItems.ListView)而不是 Table,然后一切正常。

于 2016-03-24T09:52:08.327 回答