Module: OnlyofficeWebdriverWrapper::WebdriverUserAgentHelper

Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_user_agent_helper.rb

Overview

Module for working with webdriver useragent

Constant Summary collapse

USERAGENT_ANDROID_PHONE =

Returns useragent for Android phone browser.

Returns:

  • (String)

    useragent for Android phone browser

'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MDB08M) ' \
'AppleWebKit/537.36 (KHTML, like Gecko) ' \
'Chrome/51.0.2704.81 Mobile Safari/537.36'
USERAGENT_IPHONE =

Returns useragent for iPhone browser.

Returns:

  • (String)

    useragent for iPhone browser

'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) ' \
'AppleWebKit/601.1.46 (KHTML, like Gecko) ' \
'Version/9.0 Mobile/13F69 Safari/601.1'
USERAGENT_IPAD_AIR_2_SAFARI =

Returns useragent for iPad Air 2 Safari browser.

Returns:

  • (String)

    useragent for iPad Air 2 Safari browser

'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) ' \
'AppleWebKit/602.1.50 (KHTML, like Gecko) ' \
'Version/10.0 Mobile/14A5346a Safari/602.1'
USERAGENT_NEXUS_10_CHROME =

Returns useragent for Nexus 10 Chrome browser.

Returns:

  • (String)

    useragent for Nexus 10 Chrome browser

'Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) ' \
'AppleWebKit/537.36 (KHTML, like Gecko) ' \
'Chrome/48.0.2564.23 Safari/537.36'

Instance Method Summary collapse

Instance Method Details

#add_useragent_to_switches(switches) ⇒ String

Returns user agent switch for browser.

Parameters:

  • switches (Array, String)

    current switches of browser

Returns:

  • (String)

    user agent switch for browser



43
44
45
46
47
48
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_user_agent_helper.rb', line 43

def add_useragent_to_switches(switches)
  user_agent = user_agent_for_device
  return switches.dup if user_agent.nil?

  switches.dup << "--user-agent=#{user_agent}"
end

#current_user_agentString

Returns current user agent.

Returns:

  • (String)

    current user agent



51
52
53
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_user_agent_helper.rb', line 51

def current_user_agent
  execute_javascript('return navigator.userAgent;')
end

#user_agent_for_deviceString?

Returns user agent string for current device.

Returns:

  • (String, nil)

    user agent string for current device



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_user_agent_helper.rb', line 24

def user_agent_for_device
  case @device
  when :desktop_linux
    nil
  when :android_phone
    USERAGENT_ANDROID_PHONE
  when :iphone
    USERAGENT_IPHONE
  when :ipad_air_2_safari
    USERAGENT_IPAD_AIR_2_SAFARI
  when :nexus_10_chrome
    USERAGENT_NEXUS_10_CHROME
  else
    raise("Unknown user device for starting browser: #{@device}")
  end
end