问题描述
我是 C++ 应用程序开发的初学者.我使用 Visual Studio,并且有一个应用程序可以像 Photoshop 一样处理图像.我希望通过保存处理过的文件来自动化我的应用程序的 UI 并自动测试各种场景.我在我的 Win 7 机器上使用 Visual Studio 进行开发,没有 .NET.我有哪些选项可以自动化我的测试?
I am a beginner in C++ application development. I use Visual Studio and I have an application which process the image like Photoshop does. I wish to automate the UI of my app and test various scenarios automatically by saving processed files. I use Visual studio on my Win 7 machine for development, do not have .NET. What options I have to automate my testing?
谢谢
推荐答案
在 Windows 7(和 Vista/XP,如果您安装更新)上,您可以使用基于 COM 的 Microsoft UI 自动化 API 以 C++ 编写 UI 自动化客户端.
On Windows 7 (and Vista/XP, if you install an update) you can use the COM-based Microsoft UI Automation API to write UI automation clients in C++.
我已经通过这种方式成功地自动化了 Windows 应用程序的 UI.它运行良好,甚至可以从理解 COM 的基于 C 的脚本语言解释器(例如 Python 和 Ruby)调用一些额外的工作.
I've successfully automated the UI of Windows apps this way. It works pretty well, and with a little extra work can even be called from C-based scripting language interpreters that understand COM (e.g. Python and Ruby).
在 UIA COM API 上查找文档可能有点棘手,因为搜索MS UI 自动化"通常会在 .NET 接口而不是 COM 接口上找到信息(COM 接口要新得多,而且不太知名)).
Finding documentation on the UIA COM API can be a little tricky since searches for "MS UI Automation" usually turn up info on the .NET interface rather than the COM interface (the COM interface is much newer and not as well-known).
正如 Boann 提到的,您也可以使用第三方库,例如 AutoIt.这可以缓解一些学习曲线和额外的工作.AutoIt 公开了自己的 COM 接口 (AutoItX),您可能可以从 C++ 应用程序中使用该接口.
As Boann mentions you can use third-party libraries too, like AutoIt. That can ease some of the learning curve and extra work. AutoIt exposes its own COM interface (AutoItX) that you can likely use from a C++ app.
如果您想阅读有关用 C++ 编写 COM UIA 应用程序的信息,这里有一些入门链接:
If you want to read about writing COM UIA apps in C++ here are some links to get started:
MSDN 上的 UI 自动化客户端程序员指南:
The UI Automation Client Programmer's guide on MSDN:
http://msdn.microsoft.com/en-us/library/ee684021(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ee671216(v=VS.85).aspx
IUIAutomation 接口:
The IUIAutomation interface:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee671406(v=vs.85).aspx
几篇带有示例代码的有用文章:
A couple of helpful articles with sample code:
http://www.code-magazine.com/articleprint.aspx?quickid=0810052&printmode=true
Windows 辅助功能和自动化论坛:
Windows accessibility and automation forum:
http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/threads
这篇关于在 Windows 7 平台上自动化 UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!