Class: Pincers::Chenso::Backend

Inherits:
Nokogiri::Backend show all
Defined in:
lib/pincers/chenso/backend.rb

Constant Summary

Constants inherited from Nokogiri::Backend

Nokogiri::Backend::BOOL_PROPERTIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Nokogiri::Backend

#close_document, #document_root, #document_title, #extract_element_attribute, #extract_element_html, #extract_element_tag, #extract_element_text, #search_by_css, #search_by_xpath, #set_element_attribute

Methods inherited from Pincers::Core::BaseBackend

#clear_input, #close_document, #document_root, #document_title, #double_click_on_element, #drag_and_drop, #element_is_actionable?, #elements_equal, #extract_element_attribute, #extract_element_html, #extract_element_tag, #extract_element_text, #fetch_cookies, #fetch_resource, #hover_over_element, #javascript_enabled?, #right_click_on_element, #search_by_css, #search_by_xpath, #set_element_attribute, #switch_to_parent_frame

Constructor Details

#initialize(_http_client) ⇒ Backend

Returns a new instance of Backend.



13
14
15
16
17
# File 'lib/pincers/chenso/backend.rb', line 13

def initialize(_http_client)
  super nil
  @client = _http_client
  @browser = BrowsingManager.new @client
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



11
12
13
# File 'lib/pincers/chenso/backend.rb', line 11

def browser
  @browser
end

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/pincers/chenso/backend.rb', line 11

def client
  @client
end

Instance Method Details

#as_http_clientObject



71
72
73
# File 'lib/pincers/chenso/backend.rb', line 71

def as_http_client
  @client.fork(true)
end

#click_on_element(_element, _modifiers) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pincers/chenso/backend.rb', line 51

def click_on_element(_element, _modifiers)
  case classify _element
  when :a
    navigate_link _element
  when :option
    select_option _element
  when :input_checkbox
    toggle_checkbox _element
  when :input_radio
    set_radio_button _element
  when :input_submit, :button_submit, :button
    submit_parent_form _element
  end
end

#documentObject



19
20
21
# File 'lib/pincers/chenso/backend.rb', line 19

def document
  browser.document
end

#document_urlObject



23
24
25
# File 'lib/pincers/chenso/backend.rb', line 23

def document_url
  browser.current_url
end

#merge_http_client(_client) ⇒ Object



75
76
77
78
79
80
# File 'lib/pincers/chenso/backend.rb', line 75

def merge_http_client(_client)
  @client.join _client
  if _client.content and /text\/html/ === _client.content_type
    @browser.push HtmlPageCache.new(_client.uri, _client.content)
  end
end


35
36
37
# File 'lib/pincers/chenso/backend.rb', line 35

def navigate_back(_steps)
  browser.back _steps
end


31
32
33
# File 'lib/pincers/chenso/backend.rb', line 31

def navigate_forward(_steps)
  browser.forward _steps
end


27
28
29
# File 'lib/pincers/chenso/backend.rb', line 27

def navigate_to(_url)
  browser.push new_page_request _url
end

#refresh_documentObject



39
40
41
# File 'lib/pincers/chenso/backend.rb', line 39

def refresh_document
  browser.refresh
end

#set_element_text(_element, _value) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/pincers/chenso/backend.rb', line 43

def set_element_text(_element, _value)
  case classify _element
  when :input_text, :input_password, :input_email, :input_number, :textarea
    # TODO: validations?
    set_att _element, :value, _value
  end
end

#submit_form(_element) ⇒ Object



66
67
68
69
# File 'lib/pincers/chenso/backend.rb', line 66

def submit_form(_element)
  form = new_form _element
  load_in_target form_as_request(form), form.target
end

#switch_to_frame(_element) ⇒ Object



82
83
84
85
86
# File 'lib/pincers/chenso/backend.rb', line 82

def switch_to_frame(_element)
  if _element[:src] && !browser.switch_frame(_element[:src])
    browser.load_frame(_element[:src], new_page_request(_element[:src]))
  end
end

#switch_to_top_frameObject



88
89
90
# File 'lib/pincers/chenso/backend.rb', line 88

def switch_to_top_frame
  browser.switch_top_frame
end