[Feature Request] Change screensize while running System Test

26 views
Skip to first unread message

Pierre Hedkvist

unread,
Nov 15, 2017, 6:46:39 AM11/15/17
to Ruby on Rails: Core
Hi,

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

/test/application_system_test_case.rb
require "test_helper"


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



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. :) 

eileencodes

unread,
Nov 16, 2017, 10:56:38 AM11/16/17
to Ruby on Rails: Core
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 ]
end

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

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.
Reply all
Reply to author
Forward
0 new messages