win32screenshot 1.0.10 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +2 -2
- data/CHANGES.md +177 -0
- data/Gemfile.lock +45 -38
- data/LICENSE +1 -1
- data/README.md +48 -0
- data/Rakefile +1 -1
- data/ext/{ImageMagick-License.txt → ImageMagick-7.0.9-8-portable-Q16-x86/LICENSE.txt} +103 -101
- data/ext/ImageMagick-7.0.9-8-portable-Q16-x86/convert.exe +0 -0
- data/ext/ImageMagick-7.0.9-8-portable-Q16-x86/identify.exe +0 -0
- data/ext/ImageMagick-7.0.9-8-portable-Q16-x86/mogrify.exe +0 -0
- data/lib/win32/screenshot/image.rb +6 -1
- data/lib/win32/screenshot/version.rb +5 -5
- data/lib/win32/screenshot.rb +2 -3
- data/spec/spec_helper.rb +47 -48
- data/spec/win32/screenshot/image_spec.rb +78 -68
- data/spec/win32/screenshot/take_spec.rb +151 -151
- data/win32screenshot.gemspec +25 -25
- metadata +34 -50
- data/History.rdoc +0 -104
- data/README.rdoc +0 -44
- data/ext/CORE_RL_bzlib_.dll +0 -0
- data/ext/CORE_RL_jpeg_.dll +0 -0
- data/ext/CORE_RL_lcms_.dll +0 -0
- data/ext/CORE_RL_magick_.dll +0 -0
- data/ext/CORE_RL_png_.dll +0 -0
- data/ext/CORE_RL_ttf_.dll +0 -0
- data/ext/CORE_RL_wand_.dll +0 -0
- data/ext/CORE_RL_zlib_.dll +0 -0
- data/ext/X11.dll +0 -0
- data/ext/identify.exe +0 -0
- data/ext/modules/coders/IM_MOD_RL_bmp_.dll +0 -0
- data/ext/modules/coders/IM_MOD_RL_gif_.dll +0 -0
- data/ext/modules/coders/IM_MOD_RL_jpeg_.dll +0 -0
- data/ext/modules/coders/IM_MOD_RL_png_.dll +0 -0
- data/ext/mogrify.exe +0 -0
- data/ext/msvcr100.dll +0 -0
- data/ext/vcomp100.dll +0 -0
data/lib/win32/screenshot.rb
CHANGED
@@ -7,6 +7,5 @@ require File.dirname(__FILE__) + '/screenshot/take'
|
|
7
7
|
require File.dirname(__FILE__) + '/screenshot/image'
|
8
8
|
require File.dirname(__FILE__) + '/screenshot/bitmap_maker'
|
9
9
|
|
10
|
-
#
|
11
|
-
ENV["PATH"] = "#{File.dirname(__FILE__) + "/../../ext"};#{ENV["PATH"]}"
|
12
|
-
ENV["MAGICK_CODER_MODULE_PATH"] = File.dirname(__FILE__) + "/../../ext/modules/coders"
|
10
|
+
# add bundled ImageMagick into path
|
11
|
+
ENV["PATH"] = "#{File.dirname(__FILE__) + "/../../ext/ImageMagick-7.0.9-8-portable-Q16-x86"};#{ENV["PATH"]}"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,48 +1,47 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'win32/screenshot'
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
img.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
config.
|
46
|
-
config.before(:
|
47
|
-
|
48
|
-
end
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'win32/screenshot'
|
4
|
+
require 'rspec'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module SpecHelper
|
8
|
+
HWND_TOPMOST = -1
|
9
|
+
HWND_NOTOPMOST = -2
|
10
|
+
SWP_NOSIZE = 1
|
11
|
+
SWP_NOMOVE = 2
|
12
|
+
SWP_SHOWWINDOW = 40
|
13
|
+
|
14
|
+
extend FFI::Library
|
15
|
+
ffi_lib 'user32'
|
16
|
+
ffi_convention :stdcall
|
17
|
+
|
18
|
+
# user32.dll
|
19
|
+
attach_function :set_window_pos, :SetWindowPos,
|
20
|
+
[:long, :long, :int, :int, :int, :int, :int], :bool
|
21
|
+
|
22
|
+
def save_and_verify_image(img, file=nil)
|
23
|
+
FileUtils.mkdir @temp_dir unless File.exists?(@temp_dir)
|
24
|
+
file_name = File.join @temp_dir, "#{file}.bmp"
|
25
|
+
img.write file_name
|
26
|
+
expect(img.bitmap[0..1]).to eq('BM')
|
27
|
+
end
|
28
|
+
|
29
|
+
def resize title
|
30
|
+
hwnd = RAutomation::Window.new(:title => title).hwnd
|
31
|
+
set_window_pos(hwnd,
|
32
|
+
HWND_TOPMOST,
|
33
|
+
0, 0, 150, 238,
|
34
|
+
SWP_NOMOVE)
|
35
|
+
set_window_pos(hwnd,
|
36
|
+
HWND_NOTOPMOST,
|
37
|
+
0, 0, 0, 0,
|
38
|
+
SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE)
|
39
|
+
sleep 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.include(SpecHelper)
|
45
|
+
config.before(:suite) {FileUtils.rm Dir.glob(File.join(File.dirname(__FILE__), "tmp/*"))}
|
46
|
+
config.before(:all) {@temp_dir = File.join(File.dirname(__FILE__), 'tmp')}
|
47
|
+
end
|
@@ -1,68 +1,78 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Win32::Screenshot::Image do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
IO.popen("
|
7
|
-
@
|
8
|
-
@image = Win32::Screenshot::Take.of(:window, :pid => @
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "stores raw bitmap data" do
|
12
|
-
it "#bitmap" do
|
13
|
-
@image.bitmap[0..1].
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "saving the image to the disk" do
|
18
|
-
context "saving to the bmp format" do
|
19
|
-
it "#write" do
|
20
|
-
file_path = @temp_dir + '/image.bmp'
|
21
|
-
expect {@image.write(file_path)}.to_not raise_exception
|
22
|
-
File.open(file_path, "rb") {|io| io.read}[0..1].
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "saving to the png format" do
|
27
|
-
it "#write" do
|
28
|
-
file_path = @temp_dir + '/image.png'
|
29
|
-
expect {@image.write(file_path)}.to_not raise_exception
|
30
|
-
File.open(file_path, "rb") {|io| io.read}[0..3].
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "trying to save to the unknown format" do
|
35
|
-
it "#write" do
|
36
|
-
file_path = @temp_dir + '/image.notknown'
|
37
|
-
expect {@image.write(file_path)}.
|
38
|
-
to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
|
39
|
-
File.
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "trying to save with the filename without an extension" do
|
44
|
-
it "#write" do
|
45
|
-
file_path = @temp_dir + '/image'
|
46
|
-
expect {@image.write(file_path)}.
|
47
|
-
to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
|
48
|
-
File.
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "not allowing to overwrite existing files" do
|
53
|
-
it "#write" do
|
54
|
-
file_path = @temp_dir + '/invalid-image.png'
|
55
|
-
content = "invalid content"
|
56
|
-
File.open(file_path, "w") {|io| io.write content}
|
57
|
-
expect {@image.write(file_path)}.to raise_exception("File already exists: #{file_path}!")
|
58
|
-
File.size(file_path).
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Win32::Screenshot::Image do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
IO.popen("notepad")
|
7
|
+
@notepad = RAutomation::Window.new(:title => /notepad/i).pid
|
8
|
+
@image = Win32::Screenshot::Take.of(:window, :pid => @notepad)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "stores raw bitmap data" do
|
12
|
+
it "#bitmap" do
|
13
|
+
expect(@image.bitmap[0..1]).to eq('BM')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "saving the image to the disk" do
|
18
|
+
context "saving to the bmp format" do
|
19
|
+
it "#write" do
|
20
|
+
file_path = @temp_dir + '/image.bmp'
|
21
|
+
expect {@image.write(file_path)}.to_not raise_exception
|
22
|
+
expect(File.open(file_path, "rb") {|io| io.read}[0..1]).to eq("BM")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "saving to the png format" do
|
27
|
+
it "#write" do
|
28
|
+
file_path = @temp_dir + '/image.png'
|
29
|
+
expect {@image.write(file_path)}.to_not raise_exception
|
30
|
+
expect(File.open(file_path, "rb") {|io| io.read}[0..3]).to eq("\211PNG".force_encoding(Encoding::ASCII_8BIT))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "trying to save to the unknown format" do
|
35
|
+
it "#write" do
|
36
|
+
file_path = @temp_dir + '/image.notknown'
|
37
|
+
expect {@image.write(file_path)}.
|
38
|
+
to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
|
39
|
+
expect(File.exist?(file_path)).to eq(false)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "trying to save with the filename without an extension" do
|
44
|
+
it "#write" do
|
45
|
+
file_path = @temp_dir + '/image'
|
46
|
+
expect {@image.write(file_path)}.
|
47
|
+
to raise_exception("File '#{file_path}' has to have one of the following extensions: #{Win32::Screenshot::Image::FORMATS.join(", ")}")
|
48
|
+
expect(File.exist?(file_path)).to eq(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "not allowing to overwrite existing files" do
|
53
|
+
it "#write" do
|
54
|
+
file_path = @temp_dir + '/invalid-image.png'
|
55
|
+
content = "invalid content"
|
56
|
+
File.open(file_path, "w") {|io| io.write content}
|
57
|
+
expect {@image.write(file_path)}.to raise_exception("File already exists: #{file_path}!")
|
58
|
+
expect(File.size(file_path)).to eq(content.size)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "allowing to overwrite existing files when desired" do
|
63
|
+
it "#write!" do
|
64
|
+
file_path = @temp_dir + '/overwritten-image.png'
|
65
|
+
content = "content"
|
66
|
+
File.open(file_path, "w") {|io| io.write content}
|
67
|
+
@image.write!(file_path)
|
68
|
+
expect(File.size(file_path)).to_not eq(content.size)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
after :all do
|
74
|
+
# kill in a jruby friendly way
|
75
|
+
system("taskkill /PID #{@notepad} > nul")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -1,151 +1,151 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Win32::Screenshot::Take do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
Dir.chdir("c:/program files/Internet Explorer") { IO.popen(".\\iexplore about:blank") }
|
7
|
-
IO.popen("
|
8
|
-
@iexplore = RAutomation::Window.new(:title => /internet explorer/i).pid
|
9
|
-
@
|
10
|
-
end
|
11
|
-
|
12
|
-
it "captures the foreground" do
|
13
|
-
image = Win32::Screenshot::Take.of(:foreground)
|
14
|
-
save_and_verify_image(image, 'foreground')
|
15
|
-
hwnd = Win32::Screenshot::BitmapMaker.foreground_window
|
16
|
-
[image.width, image.height].
|
17
|
-
end
|
18
|
-
|
19
|
-
it "captures an area of the foreground" do
|
20
|
-
image = Win32::Screenshot::Take.of(:foreground, :area => [30, 30, 100, 150])
|
21
|
-
save_and_verify_image(image, 'foreground_area')
|
22
|
-
image.width.
|
23
|
-
image.height.
|
24
|
-
end
|
25
|
-
|
26
|
-
it "doesn't allow to capture an area of the foreground with invalid coordinates" do
|
27
|
-
expect {Win32::Screenshot::Take.of(:foreground, :area => [0, 0, -1, 100])}.
|
28
|
-
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "captures the desktop" do
|
32
|
-
image = Win32::Screenshot::Take.of(:desktop)
|
33
|
-
save_and_verify_image(image, 'desktop')
|
34
|
-
hwnd = Win32::Screenshot::BitmapMaker.desktop_window
|
35
|
-
[image.width, image.height].
|
36
|
-
end
|
37
|
-
|
38
|
-
it "captures an area of the desktop" do
|
39
|
-
image = Win32::Screenshot::Take.of(:desktop, :area => [30, 30, 100, 150])
|
40
|
-
save_and_verify_image(image, 'desktop_area')
|
41
|
-
image.width.
|
42
|
-
image.height.
|
43
|
-
end
|
44
|
-
|
45
|
-
it "doesn't allow to capture an area of the desktop with invalid coordinates" do
|
46
|
-
expect {Win32::Screenshot::Take.of(:desktop, :area => [0, 0, -1, 100])}.
|
47
|
-
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "captures a maximized window" do
|
51
|
-
window = RAutomation::Window.new(:pid => @iexplore)
|
52
|
-
window.maximize
|
53
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
|
54
|
-
save_and_verify_image(image, 'iexplore_max')
|
55
|
-
[image.width, image.height].
|
56
|
-
end
|
57
|
-
|
58
|
-
it "captures a minimized window" do
|
59
|
-
window = RAutomation::Window.new(:pid => @
|
60
|
-
window.minimize
|
61
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @
|
62
|
-
save_and_verify_image(image, '
|
63
|
-
[image.width, image.height].
|
64
|
-
end
|
65
|
-
|
66
|
-
it "captures a small window" do
|
67
|
-
title = /Internet Explorer/
|
68
|
-
resize(title)
|
69
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
|
70
|
-
save_and_verify_image(image, 'iexplore_resized')
|
71
|
-
|
72
|
-
# we should get the size of the picture because
|
73
|
-
# screenshot doesn't include titlebar and the size
|
74
|
-
# varies between different themes and Windows versions
|
75
|
-
window = RAutomation::Window.new(:pid => @iexplore)
|
76
|
-
[image.width, image.height].
|
77
|
-
end
|
78
|
-
|
79
|
-
it "captures a window context of the window" do
|
80
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @
|
81
|
-
save_and_verify_image(image, '
|
82
|
-
window = RAutomation::Window.new(:pid => @
|
83
|
-
[image.width, image.height].
|
84
|
-
end
|
85
|
-
|
86
|
-
it "captures a client context of the window" do
|
87
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @
|
88
|
-
save_and_verify_image(image, '
|
89
|
-
window = RAutomation::Window.new(:pid => @
|
90
|
-
[image.width, image.height].
|
91
|
-
end
|
92
|
-
|
93
|
-
it "captures an area of the window" do
|
94
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @
|
95
|
-
save_and_verify_image(image, '
|
96
|
-
image.width.
|
97
|
-
image.height.
|
98
|
-
end
|
99
|
-
|
100
|
-
it "captures by the RAutomation::Window" do
|
101
|
-
window = RAutomation::Window.new(:pid => @
|
102
|
-
image = Win32::Screenshot::Take.of(:window, :rautomation => window)
|
103
|
-
save_and_verify_image(image, '
|
104
|
-
[image.width, image.height].
|
105
|
-
end
|
106
|
-
|
107
|
-
it "captures a child windows" do
|
108
|
-
window = RAutomation::Window.new(:pid => @iexplore).child(:class => "Internet Explorer_Server")
|
109
|
-
image = Win32::Screenshot::Take.of(:window, :rautomation => window)
|
110
|
-
save_and_verify_image(image, 'iexplore_child')
|
111
|
-
[image.width, image.height].
|
112
|
-
end
|
113
|
-
|
114
|
-
it "captures a whole window if window size is specified as coordinates" do
|
115
|
-
window = RAutomation::Window.new(:pid => @
|
116
|
-
expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
|
117
|
-
image = Win32::Screenshot::Take.of(:window, :rautomation => window, :area => [0, 0, expected_width, expected_height])
|
118
|
-
save_and_verify_image(image, '
|
119
|
-
image.width.
|
120
|
-
image.height.
|
121
|
-
end
|
122
|
-
|
123
|
-
it "doesn't allow to capture an area of the window with negative coordinates" do
|
124
|
-
expect {Win32::Screenshot::Take.of(:window, :pid => @
|
125
|
-
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
126
|
-
end
|
127
|
-
|
128
|
-
it "doesn't allow to capture an area of the window if coordinates are the same" do
|
129
|
-
expect {Win32::Screenshot::Take.of(:window, :pid => @
|
130
|
-
to raise_exception("specified coordinates (x1: 10, y1: 0, x2: 10, y2: 20) are invalid - cannot be x1 >= x2 or y1 >= y2!")
|
131
|
-
end
|
132
|
-
|
133
|
-
it "doesn't allow to capture an area of the window if second coordinate is smaller than first one" do
|
134
|
-
expect {Win32::Screenshot::Take.of(:window, :pid => @
|
135
|
-
to raise_exception("specified coordinates (x1: 0, y1: 10, x2: 10, y2: 9) are invalid - cannot be x1 >= x2 or y1 >= y2!")
|
136
|
-
end
|
137
|
-
|
138
|
-
it "doesn't allow to capture an area of the window with too big coordinates" do
|
139
|
-
window = RAutomation::Window.new(:pid => @
|
140
|
-
expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
|
141
|
-
expect {Win32::Screenshot::Take.of(:window, :pid => @
|
142
|
-
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: 10, y2:
|
143
|
-
end
|
144
|
-
|
145
|
-
after :all do
|
146
|
-
[@iexplore, @
|
147
|
-
# kill them in a jruby friendly way
|
148
|
-
system("taskkill /PID #{pid} > nul")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Win32::Screenshot::Take do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
Dir.chdir("c:/program files/Internet Explorer") { IO.popen(".\\iexplore about:blank") }
|
7
|
+
IO.popen("notepad")
|
8
|
+
@iexplore = RAutomation::Window.new(:title => /internet explorer/i).pid
|
9
|
+
@notepad = RAutomation::Window.new(:title => /notepad/i).pid
|
10
|
+
end
|
11
|
+
|
12
|
+
it "captures the foreground" do
|
13
|
+
image = Win32::Screenshot::Take.of(:foreground)
|
14
|
+
save_and_verify_image(image, 'foreground')
|
15
|
+
hwnd = Win32::Screenshot::BitmapMaker.foreground_window
|
16
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(hwnd, :window))
|
17
|
+
end
|
18
|
+
|
19
|
+
it "captures an area of the foreground" do
|
20
|
+
image = Win32::Screenshot::Take.of(:foreground, :area => [30, 30, 100, 150])
|
21
|
+
save_and_verify_image(image, 'foreground_area')
|
22
|
+
expect(image.width).to eq(70)
|
23
|
+
expect(image.height).to eq(120)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "doesn't allow to capture an area of the foreground with invalid coordinates" do
|
27
|
+
expect {Win32::Screenshot::Take.of(:foreground, :area => [0, 0, -1, 100])}.
|
28
|
+
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "captures the desktop" do
|
32
|
+
image = Win32::Screenshot::Take.of(:desktop)
|
33
|
+
save_and_verify_image(image, 'desktop')
|
34
|
+
hwnd = Win32::Screenshot::BitmapMaker.desktop_window
|
35
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(hwnd, :window))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "captures an area of the desktop" do
|
39
|
+
image = Win32::Screenshot::Take.of(:desktop, :area => [30, 30, 100, 150])
|
40
|
+
save_and_verify_image(image, 'desktop_area')
|
41
|
+
expect(image.width).to eq(70)
|
42
|
+
expect(image.height).to eq(120)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "doesn't allow to capture an area of the desktop with invalid coordinates" do
|
46
|
+
expect {Win32::Screenshot::Take.of(:desktop, :area => [0, 0, -1, 100])}.
|
47
|
+
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "captures a maximized window" do
|
51
|
+
window = RAutomation::Window.new(:pid => @iexplore)
|
52
|
+
window.maximize
|
53
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
|
54
|
+
save_and_verify_image(image, 'iexplore_max')
|
55
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "captures a minimized window" do
|
59
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
60
|
+
window.minimize
|
61
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @notepad)
|
62
|
+
save_and_verify_image(image, 'notepad_min')
|
63
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
64
|
+
end
|
65
|
+
|
66
|
+
it "captures a small window" do
|
67
|
+
title = /Internet Explorer/
|
68
|
+
resize(title)
|
69
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @iexplore)
|
70
|
+
save_and_verify_image(image, 'iexplore_resized')
|
71
|
+
|
72
|
+
# we should get the size of the picture because
|
73
|
+
# screenshot doesn't include titlebar and the size
|
74
|
+
# varies between different themes and Windows versions
|
75
|
+
window = RAutomation::Window.new(:pid => @iexplore)
|
76
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "captures a window context of the window" do
|
80
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @notepad, :context => :window)
|
81
|
+
save_and_verify_image(image, 'notepad_context_window')
|
82
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
83
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
84
|
+
end
|
85
|
+
|
86
|
+
it "captures a client context of the window" do
|
87
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @notepad, :context => :client)
|
88
|
+
save_and_verify_image(image, 'notepad_context_client')
|
89
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
90
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :client))
|
91
|
+
end
|
92
|
+
|
93
|
+
it "captures an area of the window" do
|
94
|
+
image = Win32::Screenshot::Take.of(:window, :pid => @notepad, :area => [30, 30, 100, 150])
|
95
|
+
save_and_verify_image(image, 'notepad_area')
|
96
|
+
expect(image.width).to eq(70)
|
97
|
+
expect(image.height).to eq(120)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "captures by the RAutomation::Window" do
|
101
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
102
|
+
image = Win32::Screenshot::Take.of(:window, :rautomation => window)
|
103
|
+
save_and_verify_image(image, 'notepad_rautomation')
|
104
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
105
|
+
end
|
106
|
+
|
107
|
+
it "captures a child windows" do
|
108
|
+
window = RAutomation::Window.new(:pid => @iexplore).child(:class => "Internet Explorer_Server")
|
109
|
+
image = Win32::Screenshot::Take.of(:window, :rautomation => window)
|
110
|
+
save_and_verify_image(image, 'iexplore_child')
|
111
|
+
expect([image.width, image.height]).to eq(Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window))
|
112
|
+
end
|
113
|
+
|
114
|
+
it "captures a whole window if window size is specified as coordinates" do
|
115
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
116
|
+
expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
|
117
|
+
image = Win32::Screenshot::Take.of(:window, :rautomation => window, :area => [0, 0, expected_width, expected_height])
|
118
|
+
save_and_verify_image(image, 'notepad_area_full_window')
|
119
|
+
expect(image.width).to eq(expected_width)
|
120
|
+
expect(image.height).to eq(expected_height)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "doesn't allow to capture an area of the window with negative coordinates" do
|
124
|
+
expect {Win32::Screenshot::Take.of(:window, :pid => @notepad, :area => [0, 0, -1, 100])}.
|
125
|
+
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: -1, y2: 100) are invalid - cannot be negative!")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "doesn't allow to capture an area of the window if coordinates are the same" do
|
129
|
+
expect {Win32::Screenshot::Take.of(:window, :pid => @notepad, :area => [10, 0, 10, 20])}.
|
130
|
+
to raise_exception("specified coordinates (x1: 10, y1: 0, x2: 10, y2: 20) are invalid - cannot be x1 >= x2 or y1 >= y2!")
|
131
|
+
end
|
132
|
+
|
133
|
+
it "doesn't allow to capture an area of the window if second coordinate is smaller than first one" do
|
134
|
+
expect {Win32::Screenshot::Take.of(:window, :pid => @notepad, :area => [0, 10, 10, 9])}.
|
135
|
+
to raise_exception("specified coordinates (x1: 0, y1: 10, x2: 10, y2: 9) are invalid - cannot be x1 >= x2 or y1 >= y2!")
|
136
|
+
end
|
137
|
+
|
138
|
+
it "doesn't allow to capture an area of the window with too big coordinates" do
|
139
|
+
window = RAutomation::Window.new(:pid => @notepad)
|
140
|
+
expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
|
141
|
+
expect {Win32::Screenshot::Take.of(:window, :pid => @notepad, :area => [0, 0, 10, 100000])}.
|
142
|
+
to raise_exception("specified coordinates (x1: 0, y1: 0, x2: 10, y2: 100000) are invalid - maximum x2: #{expected_width} and y2: #{expected_height}!")
|
143
|
+
end
|
144
|
+
|
145
|
+
after :all do
|
146
|
+
[@iexplore, @notepad].each do |pid|
|
147
|
+
# kill them in a jruby friendly way
|
148
|
+
system("taskkill /PID #{pid} > nul")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/win32screenshot.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "win32/screenshot/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "win32screenshot"
|
7
|
-
s.version = Win32::Screenshot::VERSION
|
8
|
-
s.authors = ["Jarmo Pertman", "Aslak Hellesøy"]
|
9
|
-
s.email = ["jarmo.p@gmail.com", "aslak.hellesoy@gmail.com"]
|
10
|
-
s.description = "Capture Screenshots on Windows with Ruby to bmp, gif, jpg or png formats."
|
11
|
-
s.homepage = "http://github.com/jarmo/win32screenshot"
|
12
|
-
s.summary = "Capture Screenshots on Windows with Ruby to bmp, gif, jpg or png formats."
|
13
|
-
s.files = `git ls-files`.split("\n")
|
14
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
s.license = "MIT"
|
17
|
-
|
18
|
-
s.add_dependency("ffi", "~> 1.0")
|
19
|
-
s.add_dependency("mini_magick", "~>
|
20
|
-
s.add_dependency("rautomation", "~> 0
|
21
|
-
|
22
|
-
s.add_development_dependency("rspec", "~>
|
23
|
-
s.add_development_dependency("yard")
|
24
|
-
s.add_development_dependency("rake")
|
25
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "win32/screenshot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "win32screenshot"
|
7
|
+
s.version = Win32::Screenshot::VERSION
|
8
|
+
s.authors = ["Jarmo Pertman", "Aslak Hellesøy"]
|
9
|
+
s.email = ["jarmo.p@gmail.com", "aslak.hellesoy@gmail.com"]
|
10
|
+
s.description = "Capture Screenshots on Windows with Ruby to bmp, gif, jpg or png formats."
|
11
|
+
s.homepage = "http://github.com/jarmo/win32screenshot"
|
12
|
+
s.summary = "Capture Screenshots on Windows with Ruby to bmp, gif, jpg or png formats."
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.license = "MIT"
|
17
|
+
|
18
|
+
s.add_dependency("ffi", "~> 1.15.0")
|
19
|
+
s.add_dependency("mini_magick", "~> 4.9")
|
20
|
+
s.add_dependency("rautomation", "~> 1.1.0")
|
21
|
+
|
22
|
+
s.add_development_dependency("rspec", "~> 3.10")
|
23
|
+
s.add_development_dependency("yard")
|
24
|
+
s.add_development_dependency("rake")
|
25
|
+
end
|