Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default Capybara browser window size

So, with respect to integration testing using Capybara and RSpec, I know I can do this:

page.driver.browser.manage.window.resize_to(x,y) 

per How to set Browser Window size in Rspec (Selenium) for specific RSpec tests, but is there a way to do this globally so that every test that is affected by media queries doesn't have to define this?

like image 468
CDub Avatar asked Aug 22 '13 20:08

CDub


1 Answers

A proper way to do it for all js tests is to add following inside spec_helper.rb RSpec.configure block

config.before(:each, js: true) do   Capybara.page.driver.browser.manage.window.maximize end 

to maximize the window. Change to resize_to(x,y) to set any window size.

EDIT: If you happen to be using Poltergeist the correct way to do it is

config.before(:each, js: true) do   Capybara.page.driver.browser.resize(x,y) end 
like image 80
Mike Szyndel Avatar answered Oct 07 '22 17:10

Mike Szyndel