过时的 UI 自动化树 [英] Outdated UI automation tree

查看:33
本文介绍了过时的 UI 自动化树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的原生 Microsoft UI 自动化界面 3.0(在 VC++ 2010、Win7 中)编写自动化测试仪应用程序.被测应用程序 (AUT) 是一个 WPF 应用程序.

I am trying programming an automated tester application using the new native Microsoft UI Automation interface 3.0 (in VC++ 2010, Win7). The Application Under Test (AUT) is a WPF application.

几乎一切正常...我可以安装事件处理程序,在树中导航,使用各种条件搜索元素并使用它们的模式控制找到的元素.

Almost everything works fine... I can install event handlers, navigate through the tree, search elements using various conditions and control the found elements using their patterns.

但昨天我发现了一个让我绝望的行为:通过单击主菜单按钮切换其 GUI 主面板后,我的 AUT 的 UIA 树根本没有更新.

But yesterday I found a behaviour that leaves me despaired: The UIA tree of my AUT simply is not updated after switching its GUI main panel by clicking one of its main menu buttons.

单击主菜单按钮后,我可以看到 AUT 的 GUI 中的新小部件,但 UIA 树仍然包含在单击主菜单按钮之前 存在的控件菜单按钮.(过时的)UIA 树仍然可以使用搜索功能或使用 walker 完全读取,但当然不能写入,因为小部件不再存在.

After clicking the main menu button, I can see the new widgets in the AUT's GUI but the UIA tree still contains the controls that have been there before clicking the main menu button. The (outdated) UIA tree can be still completely read using search functions or using walker but of course it can not be written since the widgets do not exist anymore.

这看起来就像是一个过时的缓存......但是我根本不使用任何缓存 UIA 函数.没有任何.绝不.无处可去.

This exactly looks like there would be an outdated cache... however I do NOT use any caching UIA functions at all. None. Never. Nowhere.

我无法以编程方式更新 UIA 树……既不能通过调用任何 UIA 函数,也不能通过重新启动测试应用程序,也不能通过来回切换 AUT 的 GUI.这不会每次都发生.有时在单击主按钮后,树似乎是最新的,并且一切正常.但是,大多数运行都失败了.只有一种(神秘的)方法可以可靠地更新 UIA 树:使用inspect.exe.当使用inspect.exe 工具简要查看AUT 的UIA 子树时,问题突然消失了,我的测试应用程序可以立即访问实际的、更新的树!当然重启AUT后问题又出现了.

I was not able to make the UIA tree update programatically... neither by calling any UIA functions nor by restarting the tester application nor by switching the AUT's GUI back and forth. This does not happen every time. Sometimes after clicking the main button the tree seems properly up-to-date and everything works fine. However most of the runs it fails. There is only one (mysterious) way that updates the UIA tree reliably: Using inspect.exe. When using inspect.exe tool for having a brief look into the AUT's UIA sub tree, the problem is suddenly gone and my tester application can access the actual, updated tree immediately! Of course the problem re-appears after restarting the AUT.

inspect.exe 如何更新 UIA 树(另一个应用程序!!!)?如何在不使用任何缓存的情况下访问消失的元素?我错过了什么?

What does inspect.exe do to make the UIA tree (of another application!!!) update? How is it possible at all to access gone elements without using any caching? What did I miss?

我真的需要帮助.

好的,还有一些发现:

  1. UISpy.exe 能够以与inspect.exe 相同的神秘方式刷新UIA 树(这尤其奇怪,因为inspect.exe 使用与我相同的本机接口,但UISpy.exe 使用.NET 接口AFAIK).这意味着这是一种系统范围和持久的 UIA 问题,而不是纯粹的原生 UIA 问题.

  1. UISpy.exe is able to refresh the UIA tree the same mysterious way inspect.exe does (this is especially strange because inspect.exe uses the same native interface as I do but UISpy.exe uses the .NET interface AFAIK). This means this is a kind of system wide and persistent UIA problem and not a pure native-UIA-problem.

如果我在切换视图之前不访问树,则不会发生此问题.IE.如果我的测试应用程序在单击主菜单按钮切换视图之前没有访问 AUT 的视图,它会毫无问题地看到新的小部件.这强烈表明本机 UIA API 存在一些缓存问题 - 即使我不知道这是如何发生的,因为我根本不缓存.有人知道是否发生了一些内部缓存吗?

The problem does not happend if I do not access the tree before switching the view. I.e. if my tester application does not access the AUT'S view before switching the view by clicking the main menu button, it sees the new widgets without problems. This strongly indicates some caching problem of the native UIA API - even if I have no idea how this could happen because I do not caching at all. Does someone know if there is some internal caching taking place?

我认为这可能是 API 错误.然而,考虑到我目前使用 Microsoft Connect 的经验,我有点迷失了那个展示者:-(

I think this could be a API bug. However considering my current experiences with Microsoft Connect I am kind of lost with that showstopper :-(

有人知道吗?

我还测试了 Snoop 工具.使用 Snoop 并不能像 Inspect 和 UISpy 那样暂时解决问题.关于Inspect.exe,还有一个细节……折叠展开AUT的子树就可以暂时治愈问题了.

I also tested the Snoop tool. Using Snoop does NOT heal the problem temporarily like Inspect and UISpy do. Regarding Inspect.exe, there is another detail... it is enough to collapse and expands the AUT's sub-tree to temporarily heal the problem.

推荐答案

好的,更新一下.UIA 只是看起来非常糟糕.我发现读取元素的内容数组和该数组的长度会更新隐藏的缓存.我还有一个案例,选项卡的子树没有更新,但可以通过切换到另一个选项卡并返回来更新(在这种情况下,按模式读取内容没有帮助).这两种情况都是可重复的,但我找不到任何方法来预测或预防它们.此外,许多第三方 WPF 组件似乎都有问题.我们最终放弃使用该 API.

Ok, update on this. UIA simply seems horribly buggy. I found that reading an element's content array and the length of that array updates the hidden caches. I also had a case where a subtree of a tab was not update but could be updated by switching to another tab and back (reading the content by pattern did NOT help in that case). Both cases were reproducable but I could not find any way to predict or prevent them. Also al lot of third party WPF components seem to be buggy. We finally gave up to use that API.

这篇关于过时的 UI 自动化树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆