Class: Crabfarm::Dsl::Surfer::SurfContext

Inherits:
SearchContext show all
Defined in:
lib/crabfarm/dsl/surfer/surf_context.rb

Constant Summary

Constants inherited from SearchContext

Crabfarm::Dsl::Surfer::SearchContext::TIMEOUT

Instance Attribute Summary

Attributes inherited from SearchContext

#parent

Instance Method Summary collapse

Methods inherited from SearchContext

#[], #classes, #each, #element!, #fill, #first, #last, #method_missing, #respond_to?, #search

Constructor Details

#initialize(_bucket) ⇒ SurfContext

Returns a new instance of SurfContext.



9
10
11
12
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 9

def initialize(_bucket)
  super nil, self
  @bucket = _bucket
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crabfarm::Dsl::Surfer::SearchContext

Instance Method Details

#cookiesObject



38
39
40
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 38

def cookies
  driver.manage.all_cookies
end

#current_uriObject



34
35
36
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 34

def current_uri
  URI.parse driver.current_url
end

#driverObject



26
27
28
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 26

def driver
  @bucket.original
end

#elementsObject



18
19
20
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 18

def elements
  [driver]
end

#goto(_url, _params = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 42

def goto(_url, _params=nil)
  _url += "?#{_params.to_query}" if _params
  retries = 0

  loop do
    begin
      @bucket.reset if retries > 0
      driver.get(_url)
      break
    rescue Timeout::Error #, Selenium::WebDriver::Error::UnknownError
      # TODO: log this
      raise if retries >= max_retries
      retries += 1
      sleep 1.0
    end
  end
end

#quitObject



30
31
32
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 30

def quit
  @bucket.reset
end

#rootObject



14
15
16
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 14

def root
  self
end

#to_htmlObject



22
23
24
# File 'lib/crabfarm/dsl/surfer/surf_context.rb', line 22

def to_html
  driver.page_source
end