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/connection.rb,
lib/steam/browser/html_unit/web_response.rb

Defined Under Namespace

Modules: Actions 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.



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

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

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#pageObject

Returns the value of attribute page.



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

def page
  @page
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#closeObject



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

def close
  @client.closeAllWindows
end

#connectionObject



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

def connection
  client.connection
end

#execute(javascript) ⇒ Object



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

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



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

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

#locate(*args, &block) ⇒ Object



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

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

#locate_in_browser(*args, &block) ⇒ Object



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

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



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

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

#requestObject



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

def request
  @request ||= Request.new
end

#within(*args, &block) ⇒ Object



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

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