win32screenshot 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/Gemfile.lock +27 -21
- data/lib/win32/screenshot/version.rb +5 -5
- data/spec/spec_helper.rb +47 -47
- data/spec/win32/screenshot/image_spec.rb +78 -78
- data/spec/win32/screenshot/take_spec.rb +151 -151
- data/win32screenshot.gemspec +25 -25
- metadata +8 -9
- data/rdoc.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9b9611193b8f4cc8d98745a6130cf16fe6fb2674e26e76a3745e34cf8de959
|
4
|
+
data.tar.gz: 278502bd7bc360a2813db04f590ee82b706eaee894cd6ce252227acb0765676e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636cfeb1613a8b84a000b1c5b449168cf398306bfbe47de4ac882ad6bfbb5e461055e921b63cc17ad4bd1f915fc6e13c582158da5518f835813f41b55662f947
|
7
|
+
data.tar.gz: 1209209433553596e94ed0a65c67becbb652756eca79ac3ff00777e5cc8b29ea8faa9eea42312303d048bd5121a985622e5aac93db1a55e86242f3fa196d92a4
|
data/CHANGES.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,39 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
win32screenshot (3.
|
5
|
-
ffi (~> 1.
|
4
|
+
win32screenshot (3.1.0)
|
5
|
+
ffi (~> 1.15.0)
|
6
6
|
mini_magick (~> 4.9)
|
7
|
-
rautomation (~> 1.
|
7
|
+
rautomation (~> 1.1.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
diff-lcs (1.
|
13
|
-
ffi (1.
|
14
|
-
mini_magick (4.
|
15
|
-
rake (
|
16
|
-
rautomation (1.
|
17
|
-
ffi (~> 1.
|
18
|
-
rspec (
|
19
|
-
rspec-core (~>
|
20
|
-
rspec-expectations (~>
|
21
|
-
rspec-mocks (~>
|
22
|
-
rspec-core (
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
ffi (1.15.5-x86-mingw32)
|
14
|
+
mini_magick (4.11.0)
|
15
|
+
rake (13.0.6)
|
16
|
+
rautomation (1.1.0)
|
17
|
+
ffi (~> 1.15.0)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.2)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.3)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.3)
|
31
|
+
webrick (1.7.0)
|
32
|
+
yard (0.9.27)
|
33
|
+
webrick (~> 1.7.0)
|
27
34
|
|
28
35
|
PLATFORMS
|
29
|
-
ruby
|
30
36
|
x86-mingw32
|
31
37
|
|
32
38
|
DEPENDENCIES
|
33
39
|
rake
|
34
|
-
rspec (~>
|
40
|
+
rspec (~> 3.10)
|
35
41
|
win32screenshot!
|
36
42
|
yard
|
37
43
|
|
38
44
|
BUNDLED WITH
|
39
|
-
|
45
|
+
2.3.3
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Win32
|
2
|
-
module Screenshot
|
3
|
-
VERSION = "3.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Win32
|
2
|
+
module Screenshot
|
3
|
+
VERSION = "3.1.0"
|
4
|
+
end
|
5
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,47 +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 '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
|
-
img.bitmap[0..1].
|
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
|
+
$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,78 +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("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
|
-
@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
|
-
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
|
-
File.size(file_path).
|
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
|
+
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("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
|
-
[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 => @notepad)
|
60
|
-
window.minimize
|
61
|
-
image = Win32::Screenshot::Take.of(:window, :pid => @notepad)
|
62
|
-
save_and_verify_image(image, 'notepad_min')
|
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 => @notepad, :context => :window)
|
81
|
-
save_and_verify_image(image, 'notepad_context_window')
|
82
|
-
window = RAutomation::Window.new(:pid => @notepad)
|
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 => @notepad, :context => :client)
|
88
|
-
save_and_verify_image(image, 'notepad_context_client')
|
89
|
-
window = RAutomation::Window.new(:pid => @notepad)
|
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 => @notepad, :area => [30, 30, 100, 150])
|
95
|
-
save_and_verify_image(image, 'notepad_area')
|
96
|
-
image.width.
|
97
|
-
image.height.
|
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
|
-
[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 => @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
|
-
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 => @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
|
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.
|
19
|
-
s.add_dependency("mini_magick", "~> 4.9")
|
20
|
-
s.add_dependency("rautomation", "~> 1.
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32screenshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarmo Pertman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.15.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.
|
27
|
+
version: 1.15.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: mini_magick
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,28 +45,28 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.
|
48
|
+
version: 1.1.0
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.1.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '3.10'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '3.10'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: yard
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- lib/win32/screenshot/image.rb
|
122
122
|
- lib/win32/screenshot/take.rb
|
123
123
|
- lib/win32/screenshot/version.rb
|
124
|
-
- rdoc.rb
|
125
124
|
- spec/spec_helper.rb
|
126
125
|
- spec/win32/screenshot/image_spec.rb
|
127
126
|
- spec/win32/screenshot/take_spec.rb
|
data/rdoc.rb
DELETED