Skip to content

Instantly share code, notes, and snippets.

@unixmonkey
Last active March 10, 2016 19:18
Show Gist options
  • Save unixmonkey/60abcf1574387535fac5 to your computer and use it in GitHub Desktop.
Save unixmonkey/60abcf1574387535fac5 to your computer and use it in GitHub Desktop.
Capybara helper to resize browser for an action, then put it back.
# Wrap some code with this block to change the browser window size
# When the block exits, it will resize to its original dimensions
# with_browser_size(1024, 768) { find('.hidden-sm').click }
def with_browser_size(width, height, &block)
window = Capybara.current_session.driver.browser.manage.window
before_size = window.size
window.resize_to(width, height)
yield
window.resize_to(before_size[:width], before_size[:height])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment