Update: As @David points out below, Chrome window resizing does not seem to work at all on Windows. I am not sure why but I will update this blog if I fix this issue.
I’m not convinced that running your automated functional tests on real or emulated mobile devices will yeild the appropriate defects for effort involved, so this gem makes it simple to run yourwatir-webdriver or selenium-webdriver tests on real browsers (:firefox and :chrome) but using mobile device user agents and resolutions, so your app thinks they’re a mobile device.
Add this line to your application’s Gemfile:
And then execute:
Or install it yourself as:
$ gem install webdriver-user-agent
An example script in selenium-webdriver:
require 'selenium-webdriver' require 'webdriver-user-agent' driver = UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape) driver.get 'http://tiffany.com' driver.current_url.should == 'http://m.tiffany.com/International.aspx'
and another example script in watir-webdriver:
require 'watir-webdriver' require 'webdriver-user-agent' driver = UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape) browser = Watir::Browser.new driver browser.goto 'tiffany.com' browser.url.should == 'http://m.tiffany.com/International.aspx'
The available options are:
- :firefox (default)
- :iphone (default)
- :portrait (default)
This is what the screenshots look like:
Tiffany.com in iPhone portrait
Tiffany.com in iPad landscape
I think this will be a useful gem for those wanting to test mobile device functionality without having to set up complex infrastructure.