IRH301010
IRH301010

Reputation: 71

Using cucumber to test the behaviour of different screen sizes (devices)

I am automating my tests using cucumber and I have a requirement to automate the behavior of our nav bar within our mobile pages as these menu options are displayed based on screen size...for example:

480px has menu a, menu b, menu c, and menu d.

320px has menu a, menu c, and menu d.

My queston is, is this possible to automate? If so has anyone got any ideas?

Thanks in advance, Ian

Upvotes: 1

Views: 1845

Answers (2)

Rimian
Rimian

Reputation: 38418

I stuck this in one of my step definitions and it worked:

if Capybara.current_driver == :selenium
  window = Capybara.current_session.driver.browser.manage.window
  window.resize_to(1200, 800)
end

I'm using Cucumber with Capybara.

Upvotes: 2

Andy Waite
Andy Waite

Reputation: 11076

Two possible options:

  • Test this with a real browser, e.g. via Selenium, which has methods to set the window size, which should be callable via the native agent method in Capybara.
  • Pass a window constraint value in as an extra query string for testing. Your production code can check for the presence of this, and use it instead of the real window size. e.g. http://example.com/products?constrain_width=480

Upvotes: 0

Related Questions