From f02c30fe0f87cf7b5abc016193774eea64908097 Mon Sep 17 00:00:00 2001 From: Jan-Joost Spanjers Date: Fri, 12 Dec 2025 17:03:17 +0100 Subject: [PATCH 1/2] [rb] add support for Chrome full page screenshot --- rb/lib/selenium/webdriver/chromium/driver.rb | 1 + rb/lib/selenium/webdriver/chromium/features.rb | 7 ++++++- .../selenium/webdriver/chrome/driver_spec.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rb/lib/selenium/webdriver/chromium/driver.rb b/rb/lib/selenium/webdriver/chromium/driver.rb index aa6af16aa0433..dfc972ea8c02a 100644 --- a/rb/lib/selenium/webdriver/chromium/driver.rb +++ b/rb/lib/selenium/webdriver/chromium/driver.rb @@ -40,6 +40,7 @@ class Driver < WebDriver::Driver DriverExtensions::HasLogs, DriverExtensions::HasLogEvents, DriverExtensions::HasPinnedScripts, + DriverExtensions::FullPageScreenshot, DriverExtensions::PrintsPage].freeze protected diff --git a/rb/lib/selenium/webdriver/chromium/features.rb b/rb/lib/selenium/webdriver/chromium/features.rb index 5333c6e21a16b..fed6cbfee91ca 100644 --- a/rb/lib/selenium/webdriver/chromium/features.rb +++ b/rb/lib/selenium/webdriver/chromium/features.rb @@ -28,7 +28,8 @@ module Features delete_network_conditions: [:delete, 'session/:session_id/chromium/network_conditions'], set_permission: [:post, 'session/:session_id/permissions'], get_available_log_types: [:get, 'session/:session_id/se/log/types'], - get_log: [:post, 'session/:session_id/se/log'] + get_log: [:post, 'session/:session_id/se/log'], + full_page_screenshot: [:get, 'session/:session_id/screenshot/full'] }.freeze def launch_app(id) @@ -93,6 +94,10 @@ def log(type) next end end + + def full_screenshot + execute :full_page_screenshot + end end # Bridge end # Chromium end # WebDriver diff --git a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb index b3c3aba0588c4..d26c4e7199d0a 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb @@ -86,6 +86,19 @@ module Chrome ensure FileUtils.rm_rf(path) end + + it 'saves a screenshot of the full page' do + driver.navigate.to url_for('printPage.html') + viewport_height = driver.execute_script('return window.innerHeight;') + + path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png" + screenshot = driver.save_screenshot(path, full_page: true) + + _width, height = png_size(screenshot) + expect(height).to be > viewport_height + ensure + FileUtils.rm_rf(path) + end end describe '#logs' do From 9b345f98ba750e7c98b0dbfb2b0eae1e2fb87364 Mon Sep 17 00:00:00 2001 From: Jan-Joost Spanjers Date: Sat, 13 Dec 2025 11:04:30 +0100 Subject: [PATCH 2/2] fixup specs --- .../selenium/webdriver/chrome/driver_spec.rb | 13 ------------- .../selenium/webdriver/takes_screenshot_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb index d26c4e7199d0a..b3c3aba0588c4 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb @@ -86,19 +86,6 @@ module Chrome ensure FileUtils.rm_rf(path) end - - it 'saves a screenshot of the full page' do - driver.navigate.to url_for('printPage.html') - viewport_height = driver.execute_script('return window.innerHeight;') - - path = "#{Dir.tmpdir}/test#{SecureRandom.urlsafe_base64}.png" - screenshot = driver.save_screenshot(path, full_page: true) - - _width, height = png_size(screenshot) - expect(height).to be > viewport_height - ensure - FileUtils.rm_rf(path) - end end describe '#logs' do diff --git a/rb/spec/integration/selenium/webdriver/takes_screenshot_spec.rb b/rb/spec/integration/selenium/webdriver/takes_screenshot_spec.rb index c242a19534a65..91c5be06ad431 100644 --- a/rb/spec/integration/selenium/webdriver/takes_screenshot_spec.rb +++ b/rb/spec/integration/selenium/webdriver/takes_screenshot_spec.rb @@ -95,18 +95,18 @@ def save_screenshot_and_assert(source, path) it 'takes full page screenshot', except: [{platform: :macosx, reason: 'showing half resolution of what expected'}], - exclusive: {browser: :firefox} do + exclusive: {browser: %i[firefox chrome edge]} do viewport_width = driver.execute_script('return window.innerWidth;') viewport_height = driver.execute_script('return window.innerHeight;') screenshot = driver.save_screenshot path, full_page: true width, height = png_size(screenshot) - expect(width).to be >= viewport_width + expect(width).to be <= viewport_width expect(height).to be > viewport_height end - it 'does not take full page screenshot', only: {browser: %i[chrome edge safari safari_preview], + it 'does not take full page screenshot', only: {browser: %i[safari safari_preview], reason: 'these browsers do not implement this feature'} do expect { driver.save_screenshot path, full_page: true