Class: Capybara::Harness::Dom::Reader
- Inherits:
-
Object
- Object
- Capybara::Harness::Dom::Reader
- Includes:
- DSL
- Defined in:
- lib/capybara/harness/dom/reader.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#finder_attr_name ⇒ Object
Returns the value of attribute finder_attr_name.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #attribute(name, options = {}, &block) ⇒ Object
-
#find_element(values = {}) ⇒ Object
Public: Scans the DOM and finds the node that represents the subject.
- #find_element_through_list(values = {}) ⇒ Object
-
#find_list ⇒ Object
Public: Scans the DOM and finds the node that represents the subject’s list element.
-
#first_in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is located first in its list.
- #has_attrs?(values = {}) ⇒ Boolean
-
#in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is in the page’s subject list.
-
#initialize ⇒ Reader
constructor
A new instance of Reader.
-
#last_in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is located last in its list.
Constructor Details
#initialize ⇒ Reader
Returns a new instance of Reader.
7 8 9 |
# File 'lib/capybara/harness/dom/reader.rb', line 7 def initialize self.attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/capybara/harness/dom/reader.rb', line 5 def attributes @attributes end |
#finder_attr_name ⇒ Object
Returns the value of attribute finder_attr_name.
5 6 7 |
# File 'lib/capybara/harness/dom/reader.rb', line 5 def finder_attr_name @finder_attr_name end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/capybara/harness/dom/reader.rb', line 5 def name @name end |
Instance Method Details
#attribute(name, options = {}, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/capybara/harness/dom/reader.rb', line 11 def attribute(name, = {}, &block) self.finder_attr_name = name.to_sym if .delete(:finder) .merge!(:derived_value_block => block) attributes[name] = Capybara::Harness::Dom::Attribute.new(name, ) end |
#find_element(values = {}) ⇒ Object
Public: Scans the DOM and finds the node that represents the subject.
18 19 20 |
# File 'lib/capybara/harness/dom/reader.rb', line 18 def find_element(values = {}) page.find(".#{name} .#{finder_attr_name}", :visible => true, :text => finder_attr.derive_value(values)).find(:xpath, ".//ancestor::*[@class='#{name}']") end |
#find_element_through_list(values = {}) ⇒ Object
27 28 29 |
# File 'lib/capybara/harness/dom/reader.rb', line 27 def find_element_through_list(values = {}) find_list.find_element(values) end |
#find_list ⇒ Object
Public: Scans the DOM and finds the node that represents the subject’s list element.
23 24 25 |
# File 'lib/capybara/harness/dom/reader.rb', line 23 def find_list find("##{selector.to_s.pluralize}") end |
#first_in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is located first in its list.
38 39 40 41 42 |
# File 'lib/capybara/harness/dom/reader.rb', line 38 def first_in_the_list? node = list.first(".#{selector}") return false if node.nil? has_attrs?(node) end |
#has_attrs?(values = {}) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/capybara/harness/dom/reader.rb', line 51 def has_attrs?(values = {}) return false unless page.has_css?(".#{name} .#{finder_attr_name}", :visible => true, :text => finder_attr.derive_value(values)) node = find_element(values) attributes.each do |attr_name, attr| text = attr.derive_value(values) return false unless node.has_css?(".#{attr_name}", :visible => true, :text => text) end true end |
#in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is in the page’s subject list.
32 33 34 35 |
# File 'lib/capybara/harness/dom/reader.rb', line 32 def in_the_list? return false unless list.has_css?(".#{selector} .#{finder_attr_name}", :text => finder_attr) has_attrs?(element(list)) end |
#last_in_the_list? ⇒ Boolean
Public: Returns true if the subject’s element is located last in its list.
45 46 47 48 49 |
# File 'lib/capybara/harness/dom/reader.rb', line 45 def last_in_the_list? node = list.all(".#{selector}").last return false if node.nil? has_attrs?(node) end |