简体   繁体   English

过时的 UI 自动化树

[英]Outdated UI automation tree

I am trying programming an automated tester application using the new native Microsoft UI Automation interface 3.0 (in VC++ 2010, Win7).我正在尝试使用新的本机 Microsoft UI 自动化界面 3.0(在 VC++ 2010、Win7 中)编写自动化测试仪应用程序。 The Application Under Test (AUT) is a WPF application.被测应用程序 (AUT) 是一个 WPF 应用程序。

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

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.但是昨天我发现了一种让我感到绝望的行为:通过单击主菜单按钮之一切换其 GUI 主面板后,我的 AUT 的 UIA 树根本没有更新。

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.单击主菜单按钮后,我可以在 AUT 的 GUI 中看到新的小部件,但 UIA 树仍然包含单击主菜单按钮之前已经存在的控件。 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 树仍然可以使用搜索功能或使用 walker 完全读取,但当然不能写入,因为小部件不再存在。

This exactly looks like there would be an outdated cache... however I do NOT use any caching UIA functions at all.这看起来就像有一个过时的缓存......但是我根本不使用任何缓存 UIA 函数。 None.没有任何。 Never.绝不。 Nowhere.无处。

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.我无法以编程方式更新 UIA 树……既不是通过调用任何 UIA 函数,也不是通过重新启动测试应用程序,也不是通过来回切换 AUT 的 GUI。 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.只有一种(神秘的)方法可以可靠地更新 UIA 树:使用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!当使用inspect.exe 工具简要查看AUT 的UIA 子树时,问题突然消失了,我的测试应用程序可以立即访问实际的、更新的树! Of course the problem re-appears after restarting the AUT.当然重启AUT后问题又出现了。

What does inspect.exe do to make the UIA tree (of another application!!!) update?检查.exe 做什么来使 UIA 树(另一个应用程序的!!!)更新? How is it possible at all to access gone elements without using any caching?如何在不使用任何缓存的情况下访问消失的元素? What did I miss?我错过了什么?

I really need help.我真的需要帮助。


Ok, some more findings:好的,还有一些发现:

  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). UISpy.exe 能够以与inspect.exe 相同的神秘方式刷新UIA 树(这尤其奇怪,因为inspect.exe 使用与我相同的本机接口,但UISpy.exe 使用.NET 接口AFAIK)。 This means this is a kind of system wide and persistent UIA problem and not a pure native-UIA-problem.这意味着这是一种系统范围和持久的 UIA 问题,而不是纯粹的原生 UIA 问题。

  2. The problem does not happend if I do not access the tree before switching the view.如果我切换视图之前没有访问树,问题就不会发生。 Ie 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.即,如果我的测试应用程序在通过单击主菜单按钮切换视图之前没有访问 AUT 的视图,它会毫无问题地看到新的小部件。 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.这强烈表明本机 UIA API 存在一些缓存问题 - 即使我不知道这是如何发生的,因为我根本不缓存。 Does someone know if there is some internal caching taking place?有人知道是否有一些内部缓存发生吗?

I think this could be a API bug.我认为这可能是一个 API 错误。 However considering my current experiences with Microsoft Connect I am kind of lost with that showstopper :-(然而,考虑到我目前使用 Microsoft Connect 的经验,我有点迷失了那个展示者:-(

Someone any idea?有人有什么想法吗?


I also tested the Snoop tool.我还测试了 Snoop 工具。 Using Snoop does NOT heal the problem temporarily like Inspect and UISpy do.使用 Snoop 并不能像 Inspect 和 UISpy 那样暂时解决问题。 Regarding Inspect.exe, there is another detail... it is enough to collapse and expands the AUT's sub-tree to temporarily heal the problem.关于Inspect.exe,还有一个细节……折叠和展开AUT的子树足以暂时治愈问题。

Ok, update on this.好的,更新这个。 UIA simply seems horribly buggy. UIA 只是看起来非常糟糕。 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.此外,许多第三方 WPF 组件似乎都有问题。 We finally gave up to use that API.我们最终放弃了使用那个 API。

I know the question is quite old but I figured out what Inspect.exe does to refresh the UIA tree for other applications: look at the Options menu;我知道这个问题很老了,但我想出了Inspect.exe为其他应用程序刷新 UIA 树的作用:查看选项菜单; there's an item labeled SPI_SCREENREADER flag which is checked by default.默认情况下,有一个标有SPI_SCREENREADER flag的项目。

Do the following in your code and you will probably get a fresh UIA tree:在您的代码中执行以下操作,您可能会得到一个新的 UIA 树:

SystemParametersInfo( SPI_SETSCREENREADER, TRUE, NULL, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

PostMessage( HWND_BROADCAST, WM_WININICHANGE, SPI_SETSCREENREADER, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM