Mobile Devices

There are three options for using watir-webdriver to test mobile sites:

  • running tests against an embedded browser on a real device;
  • running tests against an embedded browser on a device emulator on a desktop machine; or
  • running tests against a desktop browser that is configured with the same resolution and user-agent credentials as a mobile browser.

Running against real and emulated devices (either iOS or Android) is both costly and is not as fast as using desktop browsers. There are documented details on setting up the iOS driver here and Android here. Using a real Apple device requires an Apple developer account which costs around $99.

A much easier and more efficient way is to use a desktop browser configured to mimic that of a mobile browser. This is extremely easy to do with the webdriver-user-agent gem:

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 gem currently supports firefox and chrome as desktop browsers, and iphone, ipad, android_phone, and android_tablet as devices; portrait and landscape orientations are also available.