Class: Capybara::Harness::Dom::Subject
- Inherits:
-
Object
- Object
- Capybara::Harness::Dom::Subject
- Includes:
- DSL
- Defined in:
- lib/capybara/harness/dom/subject.rb
Instance Attribute Summary collapse
-
#dom_reader ⇒ Object
Returns the value of attribute dom_reader.
-
#dom_writer ⇒ Object
Returns the value of attribute dom_writer.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#click_action(action) ⇒ Object
Public: Finds and clicks the element’s link that is assigned the data attribute for the supplied action.
- #element ⇒ Object
-
#fill_form(new_values = {}) ⇒ Object
Public: Scans the DOM and finds the node that represents the subject’s form element and fills it with the supplied values.
- #in_the_list? ⇒ Boolean
-
#initialize(dom_reader, dom_writer, values = {}) ⇒ Subject
constructor
A new instance of Subject.
- #list ⇒ Object
-
#on_the_page? ⇒ Boolean
Public: Returns true if the subject’s element is present on the page.
- #reset!(new_values = {}) ⇒ Object
Constructor Details
#initialize(dom_reader, dom_writer, values = {}) ⇒ Subject
Returns a new instance of Subject.
7 8 9 10 11 |
# File 'lib/capybara/harness/dom/subject.rb', line 7 def initialize(dom_reader, dom_writer, values = {}) self.dom_reader = dom_reader self.dom_writer = dom_writer self.values = values end |
Instance Attribute Details
#dom_reader ⇒ Object
Returns the value of attribute dom_reader.
5 6 7 |
# File 'lib/capybara/harness/dom/subject.rb', line 5 def dom_reader @dom_reader end |
#dom_writer ⇒ Object
Returns the value of attribute dom_writer.
5 6 7 |
# File 'lib/capybara/harness/dom/subject.rb', line 5 def dom_writer @dom_writer end |
#values ⇒ Object
Returns the value of attribute values.
5 6 7 |
# File 'lib/capybara/harness/dom/subject.rb', line 5 def values @values end |
Instance Method Details
#click_action(action) ⇒ Object
Public: Finds and clicks the element’s link that is assigned the data attribute for the supplied action. Common actions include :edit or :delete.
44 45 46 |
# File 'lib/capybara/harness/dom/subject.rb', line 44 def click_action(action) dom_reader.find_element(self.values).find("[data-action='#{action}']").click end |
#element ⇒ Object
29 30 31 |
# File 'lib/capybara/harness/dom/subject.rb', line 29 def element @element ||= dom_reader.find_element(self.values) end |
#fill_form(new_values = {}) ⇒ Object
Public: Scans the DOM and finds the node that represents the subject’s form element and fills it with the supplied values. It also resets the subjects current value hash has with the new values.
new_values - The values to fill the form with.
Returns nothing of interest.
19 20 21 22 |
# File 'lib/capybara/harness/dom/subject.rb', line 19 def fill_form(new_values = {}) reset!(new_values) dom_writer.fill(values) end |
#in_the_list? ⇒ Boolean
37 38 39 40 |
# File 'lib/capybara/harness/dom/subject.rb', line 37 def in_the_list? return false unless list.has_css?(".#{selector} .#{finder_attr_name}", :text => finder_attr) has_attrs?(element(list)) end |
#list ⇒ Object
33 34 35 |
# File 'lib/capybara/harness/dom/subject.rb', line 33 def list @list ||= dom_reader.find_list end |
#on_the_page? ⇒ Boolean
Public: Returns true if the subject’s element is present on the page.
25 26 27 |
# File 'lib/capybara/harness/dom/subject.rb', line 25 def on_the_page? dom_reader.has_attrs?(self.values) end |
#reset!(new_values = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/capybara/harness/dom/subject.rb', line 48 def reset!(new_values = {}) self.values = values.merge(new_values) @element = nil @list = nil end |