windows 自动截取程序窗口的截图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4751750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:02:13  来源:igfitidea点击:

Automatically taking screenshots of program window

windowsmacrosautomationscreenshotuser-manual

提问by Sergey Kornilov

I'm looking for a software that combines macro recording with screenshot taking capabilities.

我正在寻找一种将宏录制与屏幕截图功能相结合的软件。

We have a software manual with a number of screenshots. When new version of software is released we need to update most of screenshots and we have to do it manually. Now we started translating manual to several languages and number of screenshots to take have increased ten fold. We'd like to automate this process.

我们有一个带有许多屏幕截图的软件手册。当新版本的软件发布时,我们需要更新大部分截图,我们必须手动完成。现在我们开始将手册翻译成多种语言,截屏数量增加了十倍。我们想自动化这个过程。

There will be a recorded macro or something that clicks button within our software and takes screenshots of the program window. Better yet, we can specify the name of each screenshot individually though it's less important.

将有一个录制的宏或点击我们软件中的按钮并截取程序窗口屏幕截图的内容。更好的是,我们可以单独指定每个屏幕截图的名称,尽管它不太重要。

Does such a thing exist?

这样的事情存在吗?

采纳答案by PabloG

I use AutoItplus captdll.dllfor all my Windows GUI automation tasks.

我将AutoItcaptdll.dll用于我所有的 Windows GUI 自动化任务。

Example:

例子:

Run("Notepad.exe", @WindowsDir, @SW_MAXIMIZE)   ; Open NOTEPAD
Sleep(1000)
Send("Just a Test")   ; Send some text to notepad

; Save the screen to test.jpg  
$anPos = WinGetClientSize("")
$nLeft = 0
$nTop = 0
$nRight = $anPos[0]
$nBottom = $anPos[1]

$sFileName = "test.jpg"
DllCall("captdll.dll", "int:cdecl", "CaptureScreen", "str", $sFileName, "int", 85)

This way you can automate the entire screenshot capturing process:

通过这种方式,您可以自动化整个屏幕截图捕获过程:

  • start your application with Run
  • select each of your menu options with Send
  • complete each screen's data also with Send
  • capture with DllCall("captdll.dll" ....)
  • 使用 Run 启动您的应用程序
  • 使用发送选择每个菜单选项
  • 也用发送完成每个屏幕的数据
  • 使用 DllCall("captdll.dll" ....) 捕获

You can also add conditional logic, loop, etc.

您还可以添加条件逻辑、循环等。

回答by Ben

Yes. You want automated testing software, which can do all this and test your product too.

是的。您需要自动化测试软件,它可以完成所有这些工作并测试您的产品。

http://en.wikipedia.org/wiki/List_of_GUI_testing_tools

http://en.wikipedia.org/wiki/List_of_GUI_testing_tools

回答by Peladao

Testing Anywhereseems to have the functionality you need. Some words from their website:

Testing Anywhere似乎具有您需要的功能。他们网站上的一些话:

"Powerful GUI based recording capabilities and a no-programming required user interface allows testers to quickly set up even complex test cases" ...

“强大的基于 GUI 的记录功能和无需编程的用户界面允许测试人员快速设置甚至复杂的测试用例”......

"Visual log reports: Testing Anywhere's powerful Visualize option takes screenshots to create visual logs during runtime." (see here)

“可视化日志报告:Testing Anywhere 强大的可视化选项在运行时截取屏幕截图以创建可视化日志。” (看这里)

You could also try something more simple and (cheaper!) such as Jitbit Macro Recorderthat let's you play back recorded macro's (keyboard and mouse) and then use the Shift-PrintScreen key in the macro to make screenshots. It also has a macro script editor.

您还可以尝试更简单且(更便宜!)的东西,例如Jitbit Macro Recorder,它可以让您播放录制的宏(键盘和鼠标),然后在宏中使用 Shift-PrintScreen 键来制作屏幕截图。它还有一个宏脚本编辑器。

回答by jpiasetz

If it's a webapp you can use Selenium. There is a similar tools for Visual Studio's called Test Automation FX

如果它是一个 webapp,你可以使用Selenium。Visual Studio 有一个类似的工具叫做 Test Automation FX

回答by Artur Mustafin

Yoiu can look into existing Windows Automation API : UI Automation, MSDN documentation

您可以查看现有的Windows 自动化 API:UI 自动化、MSDN 文档

Run-Time Requirements

运行时要求

UI Automation is supported on the following operating systems: Windows XP, Windows Server 2003, Windows Server 2003 R2, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2.

以下操作系统支持 UI 自动化:Windows XP、Windows Server 2003、Windows Server 2003 R2、Windows Vista、Windows 7、Windows Server 2008 和 Windows Server 2008 R2。

Client applications, from simple test scripts to robust record and playback utilities, may require access to elements that are not currently instantiated, such as a file open dialog or a menu item and therefore do not exist in the UI Automation tree. These elements can only be instantiated by reproducing, or "playing back", a specific sequence of user interface (UI) actions through the use of UI Automation properties such as AutomationID, control patterns and event listeners. See Test Script Generator Samplefor an example that uses Microsoft UI Automation to generate test scripts based on user interaction with the user interface (UI).

客户端应用程序,从简单的测试脚本到强大的记录和回放实用程序,可能需要访问当前未实例化的元素,例如文件打开对话框或菜单项,因此不存在于 UI 自动化树中。这些元素只能通过使用 UI 自动化属性(例如 AutomationID、控件模式和事件侦听器)再现或“回放”特定的用户界面 (UI) 操作序列来实例化。有关使用 Microsoft UI 自动化根据用户与用户界面 (UI) 的交互生成测试脚本的示例,请参阅测试脚本生成器示例

You can use AutomationIdPropertyinside existing Visual Studio project.

您可以在现有的 Visual Studio 项目中使用AutomationIdProperty

Implementing UI Automation in a Test Application

在测试应用程序中实现 UI 自动化

  • Add the UI Automation References.
  • 添加 UI 自动化参考。

The UI Automation dll's necessary for UI Automation clients are listed here.

此处列出了 UI 自动化客户端所需的 UI 自动化 dll。

UIAutomationClient.dll provides access to the UI Automation client-side APIs.

UIAutomationClient.dll 提供对 UI 自动化客户端 API 的访问。

UIAutomationClientSideProvider.dll provides the ability to automate Win32 controls. See UI Automation Support for Standard Controls.

UIAutomationClientSideProvider.dll 提供了自动化 Win32 控件的能力。请参阅标准控件的 UI 自动化支持。

UIAutomationTypes.dll provides access to the specific types defined in UI Automation.

UIAutomationTypes.dll 提供对 UI 自动化中定义的特定类型的访问。

  • Add the System.Windows.Automation namespace.
  • 添加 System.Windows.Automation 命名空间。

This namespace contains everything UI Automation clients need to use the capabilities of UI Automation except text handling.

此命名空间包含 UI 自动化客户端使用 UI 自动化功能所需的所有内容,但文本处理除外。

  • Add the System.Windows.Automation.Text namespace.
  • 添加 System.Windows.Automation.Text 命名空间。

This namespace contains everything a UI Automation clients need to use the capabilities of UI Automation text handling.

此命名空间包含 UI 自动化客户端使用 UI 自动化文本处理功能所需的一切。

  • Find controls of interest
  • 查找感兴趣的控件

Automated test scripts locate UI Automation elements that represent controls of interest within the automation tree.

自动化测试脚本在自动化树中定位代表感兴趣控件的 UI 自动化元素。

There are multiple ways to obtain UI Automation elements with code.

有多种方法可以通过代码获取 UI 自动化元素。

Query the UI using a Condition statement. This is typically where the language-neutral AutomationIdProperty is used. Note An AutomationIdProperty can be obtained using a tool such as UISpy.exe (UI Spy) that is able to itemize the UI Automation properties of a control.

使用 Condition 语句查询 UI。这通常是使用与语言无关的 AutomationIdProperty 的地方。注意 可以使用诸如 UISpy.exe (UI Spy) 之类的工具来获取 AutomationIdProperty,该工具能够逐项列出控件的 UI 自动化属性。

Use the TreeWalkerclass to traverse the entire UI Automation tree or a subset thereof.

使用TreeWalker类遍历整个 UI 自动化树或其子集。

Track focus.

跟踪焦点。

Use the hWnd of the control.

使用控件的 hWnd。

Use screen location, such as the location of the mouse cursor.

使用屏幕位置,例如鼠标光标的位置。

See Obtaining UI Automation Elements

请参阅获取 UI 自动化元素

  • Obtain Control Patterns
  • 获取控制模式

Control patterns expose common behaviors for functionally similar controls.

控件模式公开了功能相似控件的常见行为。

After locating the controls that require testing, automated test scripts obtain the control patterns of interest from those UI Automation elements. For example, the InvokePattern control pattern for typical button functionality or the WindowPattern control pattern for window functionality.

在定位需要测试的控件后,自动化测试脚本从这些 UI 自动化元素中获取感兴趣的控件模式。例如,典型按钮功能的 InvokePattern 控件模式或窗口功能的 WindowPattern 控件模式。

See UI Automation Control Patterns Overview.

请参阅 UI 自动化控制模式概述。

  • Automate the UI
  • 自动化用户界面

Automated test scripts can now control any UI of interest from a UI framework using the information and functionality exposed by the UI Automation control patterns.

自动化测试脚本现在可以使用 UI 自动化控制模式公开的信息和功能从 UI 框架控制任何感兴趣的 UI。

Related Tools and Technologies

相关工具和技术

There are a number of related tools and technologies that support automated testing with UI Automation.

有许多相关的工具和技术支持使用 UI 自动化进行自动化测试。

UISpy.exe (UI Spy)is a graphical user interface (GUI) application that can be used to gather UI Automation information for both provider and client development and debugging. UI Spy is included in the Windows Software Development Kit (SDK).

UISpy.exe (UI Spy)是一个图形用户界面 (GUI) 应用程序,可用于为提供程序和客户端开发和调试收集 UI 自动化信息。UI Spy 包含在 Windows 软件开发工具包 (SDK) 中。

UIAutoCmd is a command-line tool with capabilities similar to UI Spy.

UIAutoCmd 是一个命令行工具,其功能类似于 UI Spy。

MSAABridge exposes UI Automation information to Active Accessibility clients. The primary goal of bridging UI Automation to Active Accessibility is to allow existing Active Accessibility clients the ability to interact with any framework that has implemented UI Automation. Security

MSAABridge 向 Active Accessibility 客户端公开 UI 自动化信息。将 UI 自动化桥接到 Active Accessibility 的主要目标是允许现有的 Active Accessibility 客户端能够与任何已实现 UI 自动化的框架进行交互。安全

For security information, see UI Automation Security Overview.

有关安全信息,请参阅 UI 自动化安全概述。

回答by smirkingman

I've tried many and the one that really stands out, in my opinion, is Adobe (formerly Macromedia) Captivate. It's atrociously expensive (~800$) but worth every penny.

我已经尝试了很多,在我看来,真正脱颖而出的是Adobe(前身为 Macromedia) Captivate。它非常昂贵(约 800 美元),但值得每一分钱。

Creating tutorials etc. takes minutes instead of hours.

创建教程等需要几分钟而不是几小时。

回答by StefanE

I would use the Open Source tool Sikuli. Pretty straight forward scripting language or you can use their classes and write your own java code.

我会使用开源工具 Sikuli。非常直接的脚本语言,或者您可以使用他们的类并编写自己的 Java 代码。

Here is the documentation to grab a part of the screen: http://sikuli.org/docx/screen.html#capturing

这是抓取屏幕一部分的文档:http: //sikuli.org/docx/screen.html#capturing

The bonus is that this is supported on Windows, Linux and Mac!

好处是它在 Windows、Linux 和 Mac 上都受支持!