Module: Waterpig::BrowserSize
- Defined in:
- lib/waterpig/browser-size.rb
Constant Summary collapse
- MIN_WIDTH =
empirically determined - there’s an issue on Chrome somewhere, but I can’t find it at the moment. The upshot is: if you resize Chrome on Linux below this width, the content area collapses to 0 height. Tests pass anyway, is the worst part.
348
- @@warned_about_size =
false
Class Method Summary collapse
Class Method Details
.current_size(example) ⇒ Object
36 37 38 |
# File 'lib/waterpig/browser-size.rb', line 36 def self.current_size(example) (example.[:size] || ENV['BROWSER_SIZE'] || :desktop).to_sym end |
.included(group) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/waterpig/browser-size.rb', line 3 def self.included(group) group.before(:each) do |example| sizes = RSpec.configuration.waterpig_browser_sizes BrowserSize.resize_browser_window(sizes[BrowserSize.current_size(example)]) end end |
.resize_browser_window(size) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/waterpig/browser-size.rb', line 18 def self.resize_browser_window(size) driver = Capybara.current_session.driver window = driver.current_window_handle width = size.fetch(:width) if width < MIN_WIDTH unless @@warned_about_size warn "Requested browser size #{size.inspect} - but minimum width is #{MIN_WIDTH}. Adjusting." warn "You might consider setting up mobile browser emulation. Try running with" warn "CAPYBARA_DRIVER=mobile_chrome_android CAPYBARA_JS_DRIVER=mobile_chrome_android" @@warned_about_size = true end width = MIN_WIDTH end req_size = [width, size.fetch(:height)] driver.resize_window_to(window, *req_size) end |