win32screenshot 1.0.10 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- # environment variables for bundled MiniMagick
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 'rubygems'
5
- require 'rspec'
6
- require 'fileutils'
7
-
8
- module SpecHelper
9
- HWND_TOPMOST = -1
10
- HWND_NOTOPMOST = -2
11
- SWP_NOSIZE = 1
12
- SWP_NOMOVE = 2
13
- SWP_SHOWWINDOW = 40
14
-
15
- extend FFI::Library
16
- ffi_lib 'user32'
17
- ffi_convention :stdcall
18
-
19
- # user32.dll
20
- attach_function :set_window_pos, :SetWindowPos,
21
- [:long, :long, :int, :int, :int, :int, :int], :bool
22
-
23
- def save_and_verify_image(img, file=nil)
24
- FileUtils.mkdir @temp_dir unless File.exists?(@temp_dir)
25
- file_name = File.join @temp_dir, "#{file}.bmp"
26
- img.write file_name
27
- img.bitmap[0..1].should == 'BM'
28
- end
29
-
30
- def resize title
31
- hwnd = RAutomation::Window.new(:title => title).hwnd
32
- set_window_pos(hwnd,
33
- HWND_TOPMOST,
34
- 0, 0, 150, 238,
35
- SWP_NOMOVE)
36
- set_window_pos(hwnd,
37
- HWND_NOTOPMOST,
38
- 0, 0, 0, 0,
39
- SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE)
40
- sleep 1
41
- end
42
- end
43
-
44
- RSpec.configure do |config|
45
- config.include(SpecHelper)
46
- config.before(:suite) {FileUtils.rm Dir.glob(File.join(File.dirname(__FILE__), "tmp/*"))}
47
- config.before(:all) {@temp_dir = File.join(File.dirname(__FILE__), 'tmp')}
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("calc")
7
- @calc = RAutomation::Window.new(:title => /calculator/i).pid
8
- @image = Win32::Screenshot::Take.of(:window, :pid => @calc)
9
- end
10
-
11
- describe "stores raw bitmap data" do
12
- it "#bitmap" do
13
- @image.bitmap[0..1].should == '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
- File.open(file_path, "rb") {|io| io.read}[0..1].should == "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
- File.open(file_path, "rb") {|io| io.read}[0..3].should == "\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
- File.should_not exist(file_path)
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.should_not exist(file_path)
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).should == content.size
59
- end
60
- end
61
- end
62
-
63
- after :all do
64
- # kill in a jruby friendly way
65
- system("taskkill /PID #{@calc} > nul")
66
- end
67
-
68
- 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("calc")
8
- @iexplore = RAutomation::Window.new(:title => /internet explorer/i).pid
9
- @calc = RAutomation::Window.new(:title => /calculator/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].should == 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
- image.width.should == 70
23
- image.height.should == 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
- [image.width, image.height].should == 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
- image.width.should == 70
42
- image.height.should == 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
- [image.width, image.height].should == Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
56
- end
57
-
58
- it "captures a minimized window" do
59
- window = RAutomation::Window.new(:pid => @calc)
60
- window.minimize
61
- image = Win32::Screenshot::Take.of(:window, :pid => @calc)
62
- save_and_verify_image(image, 'calc_min')
63
- [image.width, image.height].should == 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
- [image.width, image.height].should == 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 => @calc, :context => :window)
81
- save_and_verify_image(image, 'calc_context_window')
82
- window = RAutomation::Window.new(:pid => @calc)
83
- [image.width, image.height].should == 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 => @calc, :context => :client)
88
- save_and_verify_image(image, 'calc_context_client')
89
- window = RAutomation::Window.new(:pid => @calc)
90
- [image.width, image.height].should == 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 => @calc, :area => [30, 30, 100, 150])
95
- save_and_verify_image(image, 'calc_area')
96
- image.width.should == 70
97
- image.height.should == 120
98
- end
99
-
100
- it "captures by the RAutomation::Window" do
101
- window = RAutomation::Window.new(:pid => @calc)
102
- image = Win32::Screenshot::Take.of(:window, :rautomation => window)
103
- save_and_verify_image(image, 'calc_rautomation')
104
- [image.width, image.height].should == 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
- [image.width, image.height].should == 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 => @calc)
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, 'calc_area_full_window')
119
- image.width.should == expected_width
120
- image.height.should == 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 => @calc, :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 => @calc, :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 => @calc, :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 => @calc)
140
- expected_width, expected_height = Win32::Screenshot::BitmapMaker.dimensions_for(window.hwnd, :window)
141
- expect {Win32::Screenshot::Take.of(:window, :pid => @calc, :area => [0, 0, 10, 1000])}.
142
- to raise_exception("specified coordinates (x1: 0, y1: 0, x2: 10, y2: 1000) are invalid - maximum x2: #{expected_width} and y2: #{expected_height}!")
143
- end
144
-
145
- after :all do
146
- [@iexplore, @calc].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
@@ -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", "~> 3.5.0")
20
- s.add_dependency("rautomation", "~> 0.7")
21
-
22
- s.add_development_dependency("rspec", "~> 2.5")
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