且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Snoop 使用什么技术来检查 WPF 应用程序

更新时间:2022-11-11 23:36:22

您可以使用 WPF VisualTreeHelper 和/或 LogicalTreeHelper 来完成 Snoop 所做的事情.一旦你掌握了任何视觉元素,你几乎可以遍历它的整个视觉树来查看它包含的所有元素.可视化树助手这里

You can accomplish what Snoop does by using the WPF VisualTreeHelper and/or the LogicalTreeHelper. Once you get a hold of any visual element, you can pretty much traverse its entire visual tree to see all the elements it contains. Visual tree helper here

因此,在您的 UI 测试中,抓取主窗口并遍历其可视化树以找到您想要的任何元素,然后对该元素执行您想要的任何验证或操作.

So in your UI test, grab the main window and traverse its visual tree to find any element you want and then perform any validations or operations you want on that element.

此外,您可以使用 System.Diagnostics.Process.MainWindowHandle 从现有进程获取窗口句柄,然后使用窗口句柄创建 wpf 窗口.已经有一段时间了,所以如果没有做更多研究,我就不记得具体细节了.下面的代码可能会有所帮助:

Furthermore, you may be able to use System.Diagnostics.Process.MainWindowHandle to get the windows handle from an existing process and then use the window's handle to create a wpf window. Its been a while so I dont remember the specifics without doing more research. The code below may help:

Window window = (Window)System.Windows.Interop.HwndSource.FromHwnd(process.MainWindowHandle).RootVisual;