Module: UserAgent
- Defined in:
- lib/webdriver-user-agent.rb
Class Method Summary collapse
- .agent_string_for(device) ⇒ Object
- .devices ⇒ Object
- .driver(options = {}) ⇒ Object
- .resolution_for(device_name, orientation) ⇒ Object
Class Method Details
.agent_string_for(device) ⇒ Object
39 40 41 42 43 |
# File 'lib/webdriver-user-agent.rb', line 39 def self.agent_string_for device user_agent_string = devices[downcase_sym device][:user_agent] raise "Unsupported user agent: '#{[:agent]}'." unless user_agent_string user_agent_string end |
.devices ⇒ Object
30 31 32 |
# File 'lib/webdriver-user-agent.rb', line 30 def self.devices @devices ||= YAML.load_file File.("../device-info/devices.yaml", __FILE__) end |
.driver(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/webdriver-user-agent.rb', line 7 def self.driver ={} [:browser] ||= :firefox [:agent] ||= :iphone [:orientation] ||= :portrait user_agent_string = agent_string_for [:agent] device_resolution = resolution_for [:agent], [:orientation] case [:browser] when :firefox [:profile] ||= Selenium::WebDriver::Firefox::Profile.new [:profile]['general.useragent.override'] = user_agent_string when :chrome [:switches] ||= [] [:switches] << "--user-agent=#{user_agent_string}" else raise "WebDriver UserAgent currently only supports :firefox and :chrome." end driver = Selenium::WebDriver.for [:browser], .except(:browser, :agent, :orientation) resize_inner_window driver, *device_resolution driver end |
.resolution_for(device_name, orientation) ⇒ Object
34 35 36 37 |
# File 'lib/webdriver-user-agent.rb', line 34 def self.resolution_for device_name, orientation device = devices[downcase_sym device_name][downcase_sym orientation] [device[:width],device[:height]] end |