Change default Capybara browser window size

前端 未结 5 1987
不思量自难忘°
不思量自难忘° 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:23

    For test runtime in Capybara 2.2.4 version you can achieve this by doing

    before do
      handle = Capybara.page.driver.current_window_handle
      Capybara.page.driver.resize_window_to(handle, height, width)
    end
    

    Or

    before do   
      Capybara.page.current_window.resize_to(height, width)
    end
    

    If you get Capybara::NotSupportedByDriverError: Capybara::Driver::Base#current_window_handle YOU MUST CHANGE YOUR DRIVER FOR EXAMPLE USE JAVASCRIPT DRIVER!

    before do   
      Capybara.page.current_window.resize_to(height, width)
    end
    
    scenario js: true do
      # your test here
    end
    

提交回复
热议问题