|
13 | 13 | create_screenshot(path: file) |
14 | 14 |
|
15 | 15 | File.open(file, "rb") do |f| |
16 | | - expect(ImageSize.new(f.read).size).to eq(browser.viewport_size) |
| 16 | + expect(ImageSize.new(f.read).size).to eq(browser.viewport_size.map { |s| s * device_pixel_ratio }) |
17 | 17 | end |
18 | 18 |
|
19 | 19 | create_screenshot(path: file, full: true) |
20 | 20 |
|
21 | 21 | File.open(file, "rb") do |f| |
22 | | - expect(ImageSize.new(f.read).size).to eq( |
23 | | - browser.evaluate("[document.documentElement.clientWidth, document.documentElement.clientHeight]") |
24 | | - ) |
| 22 | + size = browser.evaluate("[document.documentElement.clientWidth, document.documentElement.clientHeight]") |
| 23 | + expect(ImageSize.new(f.read).size).to eq(size.map { |s| s * device_pixel_ratio }) |
25 | 24 | end |
26 | 25 | end |
27 | 26 |
|
|
31 | 30 | create_screenshot(path: file, full: true) |
32 | 31 |
|
33 | 32 | File.open(file, "rb") do |f| |
34 | | - expect(ImageSize.new(f.read).size).to eq(browser.viewport_size) |
| 33 | + expect(ImageSize.new(f.read).size).to eq(browser.viewport_size.map { |s| s * device_pixel_ratio }) |
35 | 34 | end |
36 | 35 | end |
37 | 36 |
|
|
48 | 47 | return [rect.width, rect.height]; |
49 | 48 | }(); |
50 | 49 | JS |
51 | | - expect(ImageSize.new(f.read).size).to eq(size) |
| 50 | + expect(ImageSize.new(f.read).size).to eq(size.map { |s| s * device_pixel_ratio }) |
52 | 51 | end |
53 | 52 | end |
54 | 53 |
|
|
59 | 58 | create_screenshot(path: file, full: true, selector: "#penultimate") |
60 | 59 |
|
61 | 60 | File.open(file, "rb") do |f| |
62 | | - expect(ImageSize.new(f.read).size).to eq( |
63 | | - browser.evaluate("[document.documentElement.clientWidth, document.documentElement.clientHeight]") |
64 | | - ) |
| 61 | + size = browser.evaluate("[document.documentElement.clientWidth, document.documentElement.clientHeight]") |
| 62 | + expect(ImageSize.new(f.read).size).to eq(size.map { |s| s * device_pixel_ratio }) |
65 | 63 | end |
66 | 64 | end |
67 | 65 |
|
|
99 | 97 | describe "#screenshot" do |
100 | 98 | let(:format) { :png } |
101 | 99 | let(:file) { "#{PROJECT_ROOT}/spec/tmp/screenshot.#{format}" } |
| 100 | + let(:device_pixel_ratio) { browser.device_pixel_ratio } |
102 | 101 |
|
103 | 102 | def create_screenshot(**options) |
104 | 103 | browser.screenshot(**options) |
@@ -165,7 +164,7 @@ def create_screenshot(**options) |
165 | 164 | browser.screenshot(path: file, full: true) |
166 | 165 |
|
167 | 166 | File.open(file, "rb") do |f| |
168 | | - expect(ImageSize.new(f.read).size).to eq([1280, 1024]) |
| 167 | + expect(ImageSize.new(f.read).size).to eq([1280, 1024].map { |s| s * device_pixel_ratio }) |
169 | 168 | end |
170 | 169 | expect(browser.viewport_size).to eq([1024, 768]) |
171 | 170 | end |
|
0 commit comments