Watir2.0.1之——屏幕截图

     现在实现的功能是ruby的截图模块。主要是通过win32screenshot gem来完成的。

首先是安装:win32screenshot

http://rubygems.org/gems/win32screenshot

gem install win32screenshot

其次就可以来进行测试了。

require 'win32/screenshot'

# Take a screenshot of the window with the specified title 用来获取特殊标题的窗口图片,比如说打开某个文件夹。
Win32::Screenshot::Take.of(:window, :title => "Windows Internet Explorer").write("image.bmp")

# Take a screenshot of the foreground 用来获取当前窗口的图片
Win32::Screenshot::Take.of(:foreground).write("image.png")

# Take a screenshot of the specified window's top-left corner's area 获取特定区域的图片
Win32::Screenshot::Take.of(:window, :title => /internet/i, :area => [10, 10, 20, 20]).write("image.jpg")

# Take a screenshot of the window with the specified handle 
Win32::Screenshot::Take.of(:window, :hwnd => 123456).write("image.gif")

# Take a screenshot of the child window with the specified internal class name 可以获取子对象的图片
Win32::Screenshot::Take.of(:rautomation, RAutomation::Window.new(:hwnd => 123456).
                          child(:class => "Internet Explorer_Server")).write("image.png")

# Use the bitmap blob for something else
image = Win32::Screenshot::Take.of(:window, :hwnd => 123456)
image.height # => height of the image
image.width  # => width of the image
image.bitmap # => bitmap blob



你可能感兴趣的:(windows,server,测试,Class,Ruby,internet)