Class: BrowserLoader
- Inherits:
-
Object
- Object
- BrowserLoader
- Defined in:
- lib/ams_layout/browser_loader.rb
Overview
Chromedriver updates can be downloaded from chromedriver.storage.googleapis.com/index.html
Class Method Summary collapse
- .chromium_exe ⇒ Object
- .init_browser(timeout = 60) ⇒ Object
- .user_data_dir ⇒ Object
- .user_data_path=(path) ⇒ Object
Class Method Details
.chromium_exe ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ams_layout/browser_loader.rb', line 88 def self.chromium_exe if Ktutils::OS.windows? # Downloaded from http://chromium.woolyss.com/ # Package: Chromium Package (32-bit) # Version: 37.0.2011.0 (272392) chromium_exe = File.absolute_path(File.join(__FILE__, '../../bin/chrome-win32/chrome.exe')) else chromium_exe = `which chromium-browser`.chomp end end |
.init_browser(timeout = 60) ⇒ Object
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 67 68 69 70 71 72 |
# File 'lib/ams_layout/browser_loader.rb', line 28 def self.init_browser timeout = 60 if ENV["BROWSER"] == "ie" browser = Watir::Browser.new :ie elsif ENV["BROWSER"] == "ff" || ENV["BROWSER"] == "firefox" browser = Watir::Browser.new :firefox else # Specify chrome browser capabilities. caps = Selenium::WebDriver::Remote::Capabilities.chrome caps['chromeOptions'] = {'binary' => chromium_exe } #caps['chromeOptions'] = {'binary' => '/opt/bin/test/chrome-27.0.1453.94.exe' } # See http://peter.sh/experiments/chromium-command-line-switches/ for a list of available switches. # See https://sites.google.com/a/chromium.org/chromedriver/capabilities for details on setting ChromeDriver caps. # NOTE: The only way I've found to stop the EULA from being displayed is to # use the user-data-dir switch and point to a dir where chrome can put the # data indicating it (EULA) has already been accepted. # ignore-certificate-errors: Ignores certificate-related errors. # disable-popup-blocking: Disable pop-up blocking. # disable-translate: Allows disabling of translate from the command line to assist with automated browser testing # no-first-run: Skip First Run tasks, whether or not it's actually the First Run. # log-level: Sets the minimum log level. Valid values are from 0 to 3: INFO = 0, WARNING = 1, LOG_ERROR = 2, LOG_FATAL = 3. # test-type: As of v35, chrome displays a message bar stating # "You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer." # --test-type is supposed to disable the display of the error. switches = %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate --no-first-run --log-level=3 --test-type] switches << "--user-data-dir=#{user_data_dir}" # Create a client so we can adjust the timeout period. client = Selenium::WebDriver::Remote::Http::Default.new # Set the browser timeout. Default is 60 seconds. client.timeout = timeout # switches and caps modify chrome (or chromium) browser, # service_args modifys chromedriver. browser = Watir::Browser.new :chrome, :switches => switches, :http_client => client, :service_log_path => user_data_dir + '/chromedriver.out', :desired_capabilities => caps end browser end |
.user_data_dir ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/ams_layout/browser_loader.rb', line 78 def self.user_data_dir # Store chrome profile at chrome-data. #user_data_dir = File.absolute_path(File.join(__FILE__, '../../../chrome-data')) user_data_dir = File.absolute_path(@user_data_path) fail "Chromium user-data directory does not exist at #{user_data_dir}" unless File.exist?(user_data_dir) user_data_dir end |
.user_data_path=(path) ⇒ Object
74 75 76 |
# File 'lib/ams_layout/browser_loader.rb', line 74 def self.user_data_path= path @user_data_path = path end |