Skip to content
A helper gem to emulate populate device user agents and resolutions when using webdriver
Branch: master
Clone or download
Latest commit edfadec Mar 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec Test using new devices Mar 25, 2019
.gitignore
.rspec made rspec output pretty Jun 6, 2013
.ruby-gemset changed to use ruby-version instead of rvmrc Jun 4, 2013
.ruby-version Update Ruby, devices, and deprecated Selenium and Safari methods Aug 9, 2018
ChangeLog Normalize STP detection strategy. Update version and maintainers Aug 21, 2018
Gemfile changed to use https for bundler Jun 4, 2013
HISTORY.md updated history and bumped version getting ready for release Jun 8, 2013
LICENSE First passing spec Mar 25, 2012
README.md Reflect change to Watir in README Jul 12, 2017
Rakefile First passing spec Mar 25, 2012
webdriver-user-agent.gemspec Bump version Mar 27, 2019

README.md

Webdriver::User::Agent

A helper gem to emulate populate device user agents and resolutions when using webdriver

Installation

Add this line to your application's Gemfile:

gem 'webdriver-user-agent'

And then execute:

$ bundle

Or install it yourself as:

$ gem install webdriver-user-agent

Usage

provides a UserAgent.driver method to return a new web-driver with user agent and screen resolution mimicking a mobile device.

Options

  • :browser
    • :firefox (default)
    • :chrome
    • :safari
  • :agent
    • :iphone (default)
    • :ipad
    • :android_phone
    • :android_tablet
    • :random
  • :orientation
    • :portrait (default)
    • :landscape

Example using selenium-webdriver

require 'selenium-webdriver'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
driver.get 'http://tiffany.com'
driver.current_url.should == 'http://m.tiffany.com/International.aspx'

Example using random user agent

require 'selenium-webdriver'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:agent => :random)
driver.execute_script('return navigator.userAgent')
# random agent like "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1"

Example using watir

require 'watir'
require 'webdriver-user-agent'
driver = Webdriver::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'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
You can’t perform that action at this time.