Class: Watirmark::Session
- Includes:
- Singleton, CucumberPostFailureBuffering
- Defined in:
- lib/watirmark/session.rb
Constant Summary collapse
- POST_WAIT_CHECKERS =
[]
Instance Method Summary collapse
- #browser ⇒ Object
- #browser=(x) ⇒ Object
- #closebrowser ⇒ Object
- #config ⇒ Object
- #default_chrome_profile ⇒ Object
- #default_firefox_profile ⇒ Object
- #getos ⇒ Object
-
#initialize ⇒ Session
constructor
set up the global variables, reading from the config file.
- #newsession ⇒ Object
- #openbrowser ⇒ Object
- #proxy_firefox_profile(hostname, port) ⇒ Object
Methods included from CucumberPostFailureBuffering
#buffer_post_failure, #catch_post_failures, #post_failure, #post_failure=
Constructor Details
#initialize ⇒ Session
set up the global variables, reading from the config file
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/watirmark/session.rb', line 49 def initialize Watirmark.add_exit_task { closebrowser if config.closebrowseronexit || config.headless @driver.quit if config.webdriver.to_s.eql? 'sauce' } if config.webdriver.to_s.eql? 'firefox' config.firefox_profile = default_firefox_profile elsif config.webdriver.to_s.eql? 'firefox_proxy' config.firefox_profile = proxy_firefox_profile(config.proxy_host, config.proxy_port) elsif config.webdriver.to_s.eql? 'chrome' config.chrome_profile = default_chrome_profile end end |
Instance Method Details
#browser ⇒ Object
36 37 38 |
# File 'lib/watirmark/session.rb', line 36 def browser Page.browser end |
#browser=(x) ⇒ Object
40 41 42 |
# File 'lib/watirmark/session.rb', line 40 def browser=(x) Page.browser = x end |
#closebrowser ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/watirmark/session.rb', line 157 def closebrowser begin Page.browser.close rescue Errno::ECONNREFUSED, Selenium::WebDriver::Error::WebDriverError # browser already closed or unavailable ensure Page.browser = nil end if @headless @headless.destroy @headless = nil end end |
#config ⇒ Object
44 45 46 |
# File 'lib/watirmark/session.rb', line 44 def config Watirmark::Configuration.instance end |
#default_chrome_profile ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/watirmark/session.rb', line 64 def default_chrome_profile download_directory = File.join(Configuration.instance.projectpath, "reports", "downloads") download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows? { :download => { :prompt_for_download => false, :default_directory => download_directory } } end |
#default_firefox_profile ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/watirmark/session.rb', line 76 def default_firefox_profile file_types = "text/comma-separated-values,text/csv,application/pdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip, application/x-stuffit, application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff, text/plain, application/vnd.ms-excel [official], application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/msexcel, application/x-msexcel, application/x-excel, application/vnd.ms-excel, application/excel, application/x-ms-excel, application/x-dos_ms_excel, text/csv, text/comma-separated-values, application/octet-stream, application/haansoftxls, application/msexcell, application/softgrid-xls, application/vnd.ms-excel, x-softmaker-pm" if Configuration.instance.default_firefox_profile Watirmark.logger.info "Using firefox profile: #{Configuration.instance.default_firefox_profile}" profile = Selenium::WebDriver::Firefox::Profile.from_name Configuration.instance.default_firefox_profile else profile = Selenium::WebDriver::Firefox::Profile.new end profile.native_events = false if Configuration.instance.projectpath download_directory = File.join(Configuration.instance.projectpath, "reports", "downloads") download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows? profile['browser.download.folderList'] = 2 # custom location profile['browser.download.dir'] = download_directory profile['browser.helperApps.neverAsk.saveToDisk'] = file_types profile['security.warn_entering_secure'] = false profile['security.warn_submit_insecure'] = false profile['security.warn_entering_secure.show_once'] = false profile['security.warn_entering_weak'] = false profile['security.warn_entering_weak.show_once'] = false profile['security.warn_leaving_secure'] = false profile['security.warn_leaving_secure.show_once'] = false profile['security.warn_viewing_mixed'] = false profile['security.warn_viewing_mixed.show_once'] = false profile['security.mixed_content.block_active_content'] = false end if config.firebug unless RbConfig::CONFIG['host_os'].match('linux') warn "Firebug with Firefox only supported on Linux" return end path = (File. "../../../bin/firefox_extensions/firebug", __FILE__) file = 'addon-1843-latest.xpi' Dir.chdir(path) do File.delete(file) if File.exists?(file) `wget https://addons.mozilla.org/firefox/downloads/latest/1843/addon-1843-latest.xpi` end profile.add_extension("#{path}/#{file}") end profile["focusmanager.testmode"] = true profile end |
#getos ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/watirmark/session.rb', line 172 def getos case RUBY_PLATFORM when /cygwin|mswin|mingw|bccwin|wince|emx/ return "windows" when /darwin/ return "mac" when /linux/ return "linux" end end |
#newsession ⇒ Object
141 142 143 144 |
# File 'lib/watirmark/session.rb', line 141 def newsession closebrowser openbrowser end |
#openbrowser ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/watirmark/session.rb', line 146 def openbrowser Watir.default_timeout = config.watir_timeout Watir.prefer_css = config.prefer_css Watir.always_locate = config.always_locate use_headless_display if config.headless Page.browser = new_watir_browser initialize_page_checkers Page.browser end |
#proxy_firefox_profile(hostname, port) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/watirmark/session.rb', line 128 def proxy_firefox_profile(hostname,port) profile = default_firefox_profile profile['network.proxy.http'] = hostname profile['network.proxy.http_port'] = port.to_i profile['network.proxy.ssl'] = hostname profile['network.proxy.ssl_port'] = port.to_i profile['network.proxy.ftp'] = hostname profile['network.proxy.ftp_port'] = port.to_i profile['network.proxy_type'] = 1 profile['network.proxy.type'] = 1 profile end |