Skip to content

Instantly share code, notes, and snippets.

@ryochin
Created June 20, 2024 02:23
Show Gist options
  • Save ryochin/f14dad6f413d5a16e59a10a9bd6904a2 to your computer and use it in GitHub Desktop.
Save ryochin/f14dad6f413d5a16e59a10a9bd6904a2 to your computer and use it in GitHub Desktop.
Rails: Rspec: save full screenshot on feature tests
def save_full_screenshot(page, path)
width = page.execute_script('return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);')
height = page.execute_script('return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);')
window = page.driver.browser.manage.window
window.resize_to width + 100, height + 100
page.save_screenshot path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment