[Feature Request] Change screensize while running System Test


I have a feature request regarding the screen size used by System test. Currently you initiate the screen size inside


require “test_helper”

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]


What if you have a mobile friendly web application, and the app is displayed differently depending on the screen size.

Could it be possible to change the size of the browser while running the test suite, this could be handy, because nobody wants to change a config files in between tests?

I have found that you can change the screen size using capybara like this. I have tested this myself, and works fine. There must be similar solutions using poltergeist and webkit as well.

Capybara.current_session.driver.browser.manage.window.resize_to(400, 400)


My initial idea would be to somehow specify in your test, what screen size you would like for your tests, and change it depending. What do you think about this?

If there is anything else that need to be done in regards to System Test, I am open for suggestion, I am eager to contribute. :slight_smile:

Now that I’m on a computer I can repost my twitter reply in case anyone comes across this and wonders the same thing. Ref https://twitter.com/PierreHedkvist/status/931139262426296321

Adding a feature to set the screen size per-test won’t work because the drivers are initialized when the test class is initialized and not the test itself. That said, generally, I think you’d be testing system tests for mobile in their own test class or perhaps in a group of tests so I suggest writing something like this:

# test/application_system_test_case.rb

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [ 1400, 1400 ]

class MobileSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [ 400, 800 ], options: { whatever other options you need for mobile to work }

In this case your mobile tests would inherit from the mobile test class and the rest of your tests would inherit from the other one.