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 --start-maximized --disable-popup-blocking --disable-infobars --no-sandbox test-type].freeze
Instance Method Summary collapse
-
#chromedriver_path ⇒ String
Path to chromedriver.
-
#start_chrome_driver ⇒ Webdriver::Chrome
Chrome webdriver.
Instance Method Details
#chromedriver_path ⇒ String
Returns path to chromedriver.
12 13 14 15 16 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb', line 12 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.
19 20 21 22 23 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 |
# File 'lib/onlyoffice_webdriver_wrapper/helpers/chrome_helper.rb', line 19 def start_chrome_driver prefs = { download: { prompt_for_download: false, default_directory: download_directory }, profile: { default_content_settings: { 'multiple-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 if ip_of_remote_server.nil? switches = add_useragent_to_switches(DEFAULT_CHROME_SWITCHES) = Selenium::WebDriver::Chrome::Options.new(args: switches, prefs: prefs) = { options: , desired_capabilities: caps, driver_path: chromedriver_path } begin driver = Selenium::WebDriver.for :chrome, 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, end driver.manage.window.size = Selenium::WebDriver::Dimension.new(headless.resolution_x, headless.resolution_y) if headless.running? 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 |