@@ -81,20 +81,32 @@ def save_screenshot_and_assert(source, path)
8181 end
8282
8383 it 'takes viewport screenshot by default' do
84- viewport_width = driver . execute_script ( "return window.innerWidth;" ) * 2
85- viewport_height = driver . execute_script ( "return window.innerHeight;" ) * 2
84+ viewport_width = driver . execute_script ( "return window.innerWidth;" )
85+ viewport_height = driver . execute_script ( "return window.innerHeight;" )
8686
8787 screenshot = driver . save_screenshot path
88- expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . to eq ( [ viewport_width , viewport_height ] )
88+
89+ if Platform . linux?
90+ expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . first . to be <= viewport_width
91+ expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . last . to be <= viewport_height
92+ else
93+ expect ( ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . first /2 ) . to be <= viewport_width
94+ expect ( ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . last /2 ) . to be <= viewport_height
95+ end
8996 end
9097
9198 it 'takes full page screenshot' , exclusive : { browser : :firefox } do
92- viewport_width = driver . execute_script ( "return window.innerWidth;" ) * 2
93- viewport_height = driver . execute_script ( "return window.innerHeight;" ) * 2
99+ viewport_width = driver . execute_script ( "return window.innerWidth;" )
100+ viewport_height = driver . execute_script ( "return window.innerHeight;" )
94101
95102 screenshot = driver . save_screenshot path , full_page : true
96- expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack1 ( 'NN' ) ) . to eq viewport_width
97- expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) . last ) . to be > viewport_height
103+ if Platform . linux?
104+ expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . first . to be >= viewport_width
105+ expect ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . last . to be > viewport_height
106+ else
107+ expect ( ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . first /2 ) . to be >= viewport_width
108+ expect ( ( File . read ( screenshot ) [ 0x10 ..0x18 ] . unpack ( 'NN' ) ) . last /2 ) . to be > viewport_height
109+ end
98110 end
99111
100112 it 'does not take full page screenshot' , exclude : { browser : :firefox } do
0 commit comments