Class: PersistentSelenium::Browser
- Inherits:
-
Capybara::Selenium::Driver
- Object
- Capybara::Selenium::Driver
- PersistentSelenium::Browser
- Defined in:
- lib/persistent_selenium/browser.rb
Instance Method Summary collapse
- #browser ⇒ Object
- #browser_initialized? ⇒ Boolean
-
#initialize(browser_type) ⇒ Browser
constructor
A new instance of Browser.
- #load_splash_page ⇒ Object
- #options ⇒ Object
- #reset! ⇒ Object
- #set_app_host(host) ⇒ Object
- #starting_page ⇒ Object
- #visit(path) ⇒ Object
Constructor Details
#initialize(browser_type) ⇒ Browser
Returns a new instance of Browser.
7 8 9 10 11 |
# File 'lib/persistent_selenium/browser.rb', line 7 def initialize(browser_type) @browser_type = browser_type.to_s.to_sym @frame_handles = {} @__found_elements__ = [] end |
Instance Method Details
#browser ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/persistent_selenium/browser.rb', line 13 def browser case @browser_type when :firefox profile = Selenium::WebDriver::Firefox::Profile.new profile['browser.cache.disk.enable'] = false profile['browser.cache.memory.enable'] = false profile['browser.cache.offline.enable'] = false profile['network.http.use-cache'] = false = { :profile => profile } when :chrome switches = %w{--disk-cache-size=1 --media-cache-size=1} PersistentSelenium.chrome_extensions.each do |extension| switches.push("--load-extension=#{extension}") end = { switches: switches } end @browser ||= Selenium::WebDriver.for(@browser_type, ) end |
#browser_initialized? ⇒ Boolean
40 41 42 |
# File 'lib/persistent_selenium/browser.rb', line 40 def browser_initialized? false end |
#load_splash_page ⇒ Object
57 58 59 |
# File 'lib/persistent_selenium/browser.rb', line 57 def load_splash_page browser.navigate.to("data:text/html;base64,#{Base64.encode64(starting_page)}") end |
#options ⇒ Object
36 37 38 |
# File 'lib/persistent_selenium/browser.rb', line 36 def {} end |
#reset! ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/persistent_selenium/browser.rb', line 61 def reset! if @browser begin @browser.manage. rescue Selenium::WebDriver::Error::UnhandledError => e # delete_all_cookies fails when we've previously gone # to about:blank, so we rescue this error and do nothing # instead. end end end |
#set_app_host(host) ⇒ Object
52 53 54 55 |
# File 'lib/persistent_selenium/browser.rb', line 52 def set_app_host(host) @app_host = host.dup load_splash_page end |
#starting_page ⇒ Object
73 74 75 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 |
# File 'lib/persistent_selenium/browser.rb', line 73 def starting_page "<html>\n <head>\n<title>Persistent Selenium -- Starting up...</title>\n<style>\n body {\n background: #444;\n }\n\n * {\n font-family: Verdana, Helvetica, sans-serif;\n }\n\n td {\n background: #ccc;\n width: 50%;\n text-align: center;\n\n border: solid #333 1px;\n border-radius: 5px;\n padding: 10px;\n }\n</style>\n </head>\n <body>\n<table width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n <tr>\n <td>\n <h1>Persistent Selenium</h1>\n <h2>Starting up...</h2>\n </td>\n </tr>\n</table>\n </body>\n</html>\n HTML\nend\n" |
#visit(path) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/persistent_selenium/browser.rb', line 44 def visit(path) if !path[/^http/] path = @app_host + path end browser.navigate.to(path) end |