Class: Klepto::Browser
- Inherits:
-
Object
- Object
- Klepto::Browser
- Includes:
- Capybara::DSL
- Defined in:
- lib/klepto/browser.rb
Instance Attribute Summary collapse
-
#url_to_structure ⇒ Object
readonly
Returns the value of attribute url_to_structure.
Instance Method Summary collapse
- #failure? ⇒ Boolean
- #fetch!(_url) ⇒ Object
-
#initialize(*args) ⇒ Browser
constructor
A new instance of Browser.
- #set_driver(using_driver) ⇒ Object
- #set_headers(headers) ⇒ Object
- #similar_url? ⇒ Boolean
- #status ⇒ Object
-
#statuses ⇒ Object
Capybara automatically follows redirects…
- #statusx ⇒ Object
- #success? ⇒ Boolean
- #use_driver ⇒ Object
- #was_redirected? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Browser
Returns a new instance of Browser.
6 7 8 9 |
# File 'lib/klepto/browser.rb', line 6 def initialize(*args) Klepto.logger.debug("===== Initializing new browser. =====") super end |
Instance Attribute Details
#url_to_structure ⇒ Object (readonly)
Returns the value of attribute url_to_structure.
5 6 7 |
# File 'lib/klepto/browser.rb', line 5 def url_to_structure @url_to_structure end |
Instance Method Details
#failure? ⇒ Boolean
31 32 33 |
# File 'lib/klepto/browser.rb', line 31 def failure? !success? end |
#fetch!(_url) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/klepto/browser.rb', line 56 def fetch!(_url) @url_to_structure = _url Klepto.logger.debug("Fetching (#{@use_driver}) #{@url_to_structure}") visit @url_to_structure page end |
#set_driver(using_driver) ⇒ Object
11 12 13 |
# File 'lib/klepto/browser.rb', line 11 def set_driver(using_driver) @use_driver = .current_driver = .javascript_driver = using_driver end |
#set_headers(headers) ⇒ Object
19 20 21 |
# File 'lib/klepto/browser.rb', line 19 def set_headers(headers) page.driver.headers = headers end |
#similar_url? ⇒ Boolean
39 40 41 |
# File 'lib/klepto/browser.rb', line 39 def similar_url? @url_to_structure.downcase == page.current_url.downcase end |
#status ⇒ Object
23 24 25 |
# File 'lib/klepto/browser.rb', line 23 def status page.status_code end |
#statuses ⇒ Object
Capybara automatically follows redirects… Checking the page here to see if it has changed, and if so add it on to the stack of statuses. statuses is an array because it holds the actually HTTP response code and an approximate code (2xx for example). :redirect will be pushed onto the stack if a redirect happened.
48 49 50 |
# File 'lib/klepto/browser.rb', line 48 def statuses [status, statusx] end |
#statusx ⇒ Object
52 53 54 |
# File 'lib/klepto/browser.rb', line 52 def statusx page.status_code.to_s[0..-3] + "xx" end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/klepto/browser.rb', line 27 def success? page.status_code == 200 end |
#use_driver ⇒ Object
15 16 17 |
# File 'lib/klepto/browser.rb', line 15 def use_driver @use_driver || :poltergeist end |
#was_redirected? ⇒ Boolean
35 36 37 |
# File 'lib/klepto/browser.rb', line 35 def was_redirected? @url_to_structure != page.current_url end |