Module: OnlyofficeWebdriverWrapper::ChromeHelper

Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb

Overview

Class for working with Chrome

Constant Summary collapse

DEFAULT_CHROME_SWITCHES =
%w[--kiosk-printing
--disable-popup-blocking
--disable-infobars
--no-sandbox
test-type].freeze

Instance Method Summary collapse

Instance Method Details

#chrome_service ⇒ Object



19
20
21
# File 'lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb', line 19

def chrome_service
  @chrome_service ||= Selenium::WebDriver::Chrome::Service.new(path: chromedriver_path)
end

#chromedriver_path ⇒ String

Returns path to chromedriver.

Returns:

  • path to chromedriver



13
14
15
16
17
# File 'lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb', line 13

def chromedriver_path
  driver_name = 'bin/chromedriver'
  driver_name = 'bin/chromedriver_mac' if OSHelper.mac?
  File.join(File.dirname(__FILE__), driver_name)
end

#start_chrome_driver ⇒ Webdriver::Chrome

Returns Chrome webdriver.

Returns:

  • Chrome webdriver



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb', line 24

def start_chrome_driver
  prefs = {
    download: {
      prompt_for_download: false,
      default_directory: download_directory
    },
    profile: {
      default_content_setting_values: {
        'automatic_downloads': 1
      }
    },
    credentials_enable_service: false
  }
  caps = Selenium::WebDriver::Remote::Capabilities.chrome
  caps[:logging_prefs] = { browser: 'ALL' }
  caps[:proxy] = Selenium::WebDriver::Proxy.new(ssl: "#{@proxy.proxy_address}:#{@proxy.proxy_port}") if @proxy
  caps['chromeOptions'] = { w3c: false }
  if ip_of_remote_server.nil?
    switches = add_useragent_to_switches(DEFAULT_CHROME_SWITCHES)
    options = Selenium::WebDriver::Chrome::Options.new(args: switches,
                                                       prefs: prefs)
    webdriver_options = { options: options,
                          desired_capabilities: caps,
                          service: chrome_service }
    begin
      driver = Selenium::WebDriver.for :chrome, webdriver_options
    rescue Selenium::WebDriver::Error::WebDriverError,
           Net::ReadTimeout,
           Errno::ECONNREFUSED => e
      OnlyofficeLoggerHelper.log("Starting chrome failed with error: #{e.backtrace}")
      sleep 10
      driver = Selenium::WebDriver.for :chrome, webdriver_options
    end
    maximize_chrome(driver)
    driver
  else
    caps['chromeOptions'] = {
      profile: data['zip'],
      extensions: data['extensions']
    }
    Selenium::WebDriver.for(:remote, url: 'http://' + remote_server + ':4444/wd/hub', desired_capabilities: caps)
  end
end