Class: Steam::Browser::HtmlUnit

Inherits:
Object
  • Object
show all
Includes:
Actions
Defined in:
lib/steam/browser/html_unit.rb,
lib/steam/browser/html_unit/drb.rb,
lib/steam/browser/html_unit/page.rb,
lib/steam/browser/html_unit/client.rb,
lib/steam/browser/html_unit/actions.rb,
lib/steam/browser/html_unit/handler.rb,
lib/steam/browser/html_unit/connection.rb,
lib/steam/browser/html_unit/web_response.rb

Defined Under Namespace

Modules: Actions, Handler Classes: Client, Connection, Drb, Page, WebResponse

Constant Summary

Constants included from Actions

Actions::DATE_TIME_CODE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actions

#attach_file, #blur, #check, #choose, #click_area, #click_button, #click_link, #click_on, #double_click, #drag, #drag_and_drop, #drop, #fill_in, #focus, #hover, #select, #select_date, #select_datetime, #select_time, #set_hidden_field, #submit_form, #uncheck

Constructor Details

#initialize(*args) ⇒ HtmlUnit

Returns a new instance of HtmlUnit.



25
26
27
# File 'lib/steam/browser/html_unit.rb', line 25

def initialize(*args)
  @client = Client.new(*args)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



23
24
25
# File 'lib/steam/browser/html_unit.rb', line 23

def client
  @client
end

#pageObject

Returns the value of attribute page.



23
24
25
# File 'lib/steam/browser/html_unit.rb', line 23

def page
  @page
end

#responseObject

Returns the value of attribute response.



23
24
25
# File 'lib/steam/browser/html_unit.rb', line 23

def response
  @response
end

Instance Method Details



87
88
89
# File 'lib/steam/browser/html_unit.rb', line 87

def add_cookie(name, value)
  @client.add_cookie(name, value)
end

#clear_cookiesObject



91
92
93
# File 'lib/steam/browser/html_unit.rb', line 91

def clear_cookies
  @client.clear_cookies
end

#closeObject



33
34
35
# File 'lib/steam/browser/html_unit.rb', line 33

def close
  @client.closeAllWindows
end

#connectionObject



29
30
31
# File 'lib/steam/browser/html_unit.rb', line 29

def connection
  client.connection
end

#execute(javascript) ⇒ Object



53
54
55
# File 'lib/steam/browser/html_unit.rb', line 53

def execute(javascript)
  page.execute(javascript) # FIXME does execute return a page so we need to respond?
end

#get(url) ⇒ Object Also known as: visit



41
42
43
# File 'lib/steam/browser/html_unit.rb', line 41

def get(url)
  perform(:get, url)
end


83
84
85
# File 'lib/steam/browser/html_unit.rb', line 83

def get_cookie(name)
  @client.get_cookie(name)
end

#locate(*args, &block) ⇒ Object



57
58
59
# File 'lib/steam/browser/html_unit.rb', line 57

def locate(*args, &block)
  Locator.locate(dom, *args, &block) || raise(ElementNotFound.new(*args))
end

#locate_in_browser(*args, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/steam/browser/html_unit.rb', line 61

def locate_in_browser(*args, &block)
  if args.first.respond_to?(:_classname)     # native HtmlUnit element
    args.first
  elsif args.first.respond_to?(:xpath)       # Locator element
    silence_warnings { page.getFirstByXPath(args.first.xpath) }
  else
    locate_in_browser(locate(*args, &block)) # something else
  end
end

#perform(method, uri) ⇒ Object



46
47
48
49
50
51
# File 'lib/steam/browser/html_unit.rb', line 46

def perform(method, uri)
  respond_to do
    request.update(:method => method, :uri => uri)
    client.get(request)
  end.to_a
end

#remove_handler(type) ⇒ Object



79
80
81
# File 'lib/steam/browser/html_unit.rb', line 79

def remove_handler(type)
  @client.remove_handler(type)
end

#requestObject



37
38
39
# File 'lib/steam/browser/html_unit.rb', line 37

def request
  @request ||= Request.new
end

#set_handler(type, &block) ⇒ Object

TODO use delegate



75
76
77
# File 'lib/steam/browser/html_unit.rb', line 75

def set_handler(type, &block) # TODO use delegate
  @client.set_handler(type, &block)
end

#within(*args, &block) ⇒ Object



71
72
73
# File 'lib/steam/browser/html_unit.rb', line 71

def within(*args, &block)
  Locator.within(response.body, *args, &block)
end