使用 White UI 框架在表单上找不到 DataGrid

发布于 2025-01-06 08:11:40 字数 462 浏览 1 评论 0原文

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

我决定使用 White 作为测试 UI 框架。 白色框架显示 3 条记录的 DataGrid 控件(注意:这不是 DataGridView)

现在一切都很好,除了我似乎无法找到使用我使用 VisualUIAVerify 应用程序的 验证 DataGrid 确实在表单上,​​并且它的 UI 项目类型为“Table”,并且我明确使用了控件的正确 AutomationId,但仍然没有运气。

正如前面提到的,我可以找到表单上除 DataGrid 之外的所有控件。我做错了什么吗?或者说小白根本不支持DataGrid。

任何帮助都会很棒。谢谢

鲍比

Few days ago I received a requirement to create automated UI test cases for my Windows Application (framework 2.0).

I decided to use White as the testing UI framework. Now everything works great except I cannot seem to find the DataGrid control which is displaying 3 records (note: this is not DataGridView) using the White framework

I have used VisualUIAVerify application to validate that indeed the DataGrid is on the form and it is of UI Item Type “Table” and I am defineltly using the correct AutomationId for the control but still no luck.

As mentioned before I can find all the controls on the form except DataGrid. Am I doing some thing wrong ? Or is it that white simply does not support DataGrid.

Any help will be great. Thanks

Bobby

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

み零 2025-01-13 08:11:40

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

At the end had to upgrade my application to use DataGridView control rather then using DataGrid. This seemed to fix the problem as White does not seem to support DataGrid

等待我真够勒 2025-01-13 08:11:40

我需要从 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++;
}

I needed access to a dataGrid from White and haven't figured out why White won't work (I have the source and if I have time and dig through it) however, I have written some basic code to extract the grid data into an array. Thankfully the White framework provides access to the AutomationElement.

The code below is not optimised... it was knocked together in 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++;
}
薄荷港 2025-01-13 08:11:40

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

我的问题的解决方案是告诉 White 获取一个 ListView 项目(即 TestStack.White.UIItems.ListView)而不是一个 Table,然后一切就都成功了。

I'm not sure if you have exactly the same problem as me because I don't have enough of your code, but I was struggling with this same thing with a WPF application where I was trying to access a DataGrid which was actually written as a GridView item that lived inside a ListView.

The solution to my problem was to tell White to get a ListView item (i.e. TestStack.White.UIItems.ListView) rather than a Table, then it all worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文