Change default Capybara browser window size

前端 未结 5 2009
不思量自难忘°
不思量自难忘° 2021-01-01 09:44

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)

pe

5条回答
  •  死守一世寂寞
    2021-01-01 10:45

    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
    

提交回复
热议问题