Class: Isomorfeus::Puppetmaster::Node
- Inherits:
-
Object
- Object
- Isomorfeus::Puppetmaster::Node
- Extended by:
- SelfForwardable
- Defined in:
- lib/isomorfeus/puppetmaster/node.rb
Direct Known Subclasses
Constant Summary collapse
- SUPPORTED_HTML_ELEMENTS =
%w[ a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins kbd label legend li link main map mark meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt rtc ruby s samp script section select small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr ].freeze
- SUPPORTED_SVG_ELEMENTS =
www.w3.org/TR/SVG11/eltindex.html elements listed above not mentioned a second time
%w[ altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform circle clipPath color-profile cursor defs desc ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject g glyph glyphRef hkern image line linearGradient marker mask metadata missing-glyph mpath path pattern polygon polyline radialGradient rect script set stop style svg switch symbol text textPath tref tspan use view vkern ].freeze
- SUPPORTED_HTML_AND_SVG_ELEMENTS =
(SUPPORTED_HTML_ELEMENTS + SUPPORTED_SVG_ELEMENTS).freeze
Instance Attribute Summary collapse
-
#css_selector ⇒ Object
readonly
Returns the value of attribute css_selector.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#xpath_query ⇒ Object
readonly
Returns the value of attribute xpath_query.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](attribute) ⇒ Object
- #evaluate_ruby(ruby_source = '', &block) ⇒ Object
- #evaluate_with_opal(ruby_source = '', &block) ⇒ Object
- #get_attribute(attribute) ⇒ Object
- #get_property(property) ⇒ Object
- #has_content?(content, **options) ⇒ Boolean
- #has_css?(selector, **options) ⇒ Boolean
- #has_text?(text, **options) ⇒ Boolean
- #has_xpath?(query, **options) ⇒ Boolean
- #html ⇒ Object
-
#initialize(driver, document, node_data) ⇒ Node
constructor
A new instance of Node.
- #inner_html ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #open_document_by(&block) ⇒ Object
- #parents ⇒ Object
- #respond_to?(name, include_private = false) ⇒ Boolean
- #within(&block) ⇒ Object
Methods included from SelfForwardable
Constructor Details
#initialize(driver, document, node_data) ⇒ Node
Returns a new instance of Node.
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 121 def initialize(driver, document, node_data) @css_selector = node_data[:css_selector] || node_data['css_selector'] @document = document @driver = driver @handle = node_data[:handle] || node_data['handle'] @name = node_data[:name] || node_data['name'] @tag = node_data[:tag] || node_data['tag'] @type = node_data[:type] || node_data['type'] @xpath_query = node_data[:xpath_query] || node_data['xpath_query'] ObjectSpace.define_finalizer(self, @driver.class.node_handle_disposer(@driver, @element_handle)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 217 def method_missing(name, *args) method_name = name.to_s if method_name.start_with?('find_by_') what = method_name[8..-1] return find("[#{what}=\"#{args.first}\"]") if %w[name type value].include?(what) return find_xpath("//*[text()=\"#{args.first}\"]") if what == 'content' # elsif method_name.start_with?('has_') # :has_checked_field?, # # :has_content?, # :has_css?, # :has_field?, # :has_link?, # :has_select?, # :has_selector?, # :has_table?, # :has_text?, # :has_unchecked_field?, # :has_xpath?, # :has_button?, # method_missing end super(name, *args) end |
Instance Attribute Details
#css_selector ⇒ Object (readonly)
Returns the value of attribute css_selector.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def css_selector @css_selector end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def document @document end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def handle @handle end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def name @name end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def tag @tag end |
#xpath_query ⇒ Object (readonly)
Returns the value of attribute xpath_query.
87 88 89 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 87 def xpath_query @xpath_query end |
Class Method Details
.new_by_tag(driver, document, node_data) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 96 def self.new_by_tag(driver, document, node_data) tag = node_data[:tag] || node_data['tag'] case tag when 'iframe' then Isomorfeus::Puppetmaster::Iframe.new(driver, document, node_data) when 'input' type = node_data[:type] || node_data['type'] case type when 'checkbox' then Isomorfeus::Puppetmaster::Checkbox.new(driver, document, node_data) when 'filechooser' then Isomorfeus::Puppetmaster::Filechooser.new(driver, document, node_data) when 'radiobutton' then Isomorfeus::Puppetmaster::Radiobutton.new(driver, document, node_data) when 'select' then Isomorfeus::Puppetmaster::Select.new(driver, document, node_data) else Isomorfeus::Puppetmaster::Input.new(driver, document, node_data) end when 'textarea' then Isomorfeus::Puppetmaster::Textarea.new(driver, document, node_data) else content_editable = node_data[:content_editable] || node_data['content_editable'] if content_editable Isomorfeus::Puppetmaster::ContentEditable.new(driver, document, node_data) else Isomorfeus::Puppetmaster::Node.new(driver, document, node_data) end end end |
Instance Method Details
#==(other) ⇒ Object
137 138 139 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 137 def ==(other) @driver.node_equal(self, other) end |
#[](attribute) ⇒ Object
133 134 135 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 133 def [](attribute) get_attribute(attribute) end |
#evaluate_ruby(ruby_source = '', &block) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 141 def evaluate_ruby(ruby_source = '', &block) ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given? compiled_ruby = compile_ruby_source(ruby_source) if compiled_ruby.start_with?('/*') start_of_code = compiled_ruby.index('*/') + 3 compiled_ruby = compiled_ruby[start_of_code..-1] end evaluate_script <<~JAVASCRIPT (function(){ return #{compiled_ruby} })() JAVASCRIPT end |
#evaluate_with_opal(ruby_source = '', &block) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 155 def evaluate_with_opal(ruby_source = '', &block) ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given? compiled_ruby = compile_ruby_source(ruby_source) if compiled_ruby.start_with?('/*') start_of_code = compiled_ruby.index('*/') + 3 compiled_ruby = compiled_ruby[start_of_code..-1] end evaluate_script <<~JAVASCRIPT (function(){ if (typeof Opal === "undefined") { #{Isomorfeus::Puppetmaster.opal_prelude} } return #{compiled_ruby} })() JAVASCRIPT end |
#get_attribute(attribute) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 172 def get_attribute(attribute) attribute = attribute.to_s if !(attribute.start_with?('aria-') || attribute.start_with?('data-')) attribute = attribute.camelize(:lower) end @driver.node_get_attribute(self, attribute) end |
#get_property(property) ⇒ Object
180 181 182 183 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 180 def get_property(property) property = property.to_s.camelize(:lower) @driver.node_get_property(self, property) end |
#has_content?(content, **options) ⇒ Boolean
185 186 187 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 185 def has_content?(content, **) visible_text.include?(content) end |
#has_css?(selector, **options) ⇒ Boolean
189 190 191 192 193 194 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 189 def has_css?(selector, **) res = find_all(selector) return false unless res return false if .key?(:count) && [:count] != res.size return true end |
#has_text?(text, **options) ⇒ Boolean
196 197 198 199 200 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 196 def has_text?(text, **) count = visible_text.scan(/#{text}/).size return false if .key?(:count) && [:count] != count count > 0 end |
#has_xpath?(query, **options) ⇒ Boolean
202 203 204 205 206 207 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 202 def has_xpath?(query, **) res = find_all_xpath(query) return false unless res return false if .key?(:count) && [:count] != res.size return true end |
#html ⇒ Object
209 210 211 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 209 def html get_property(:outerHTML) end |
#inner_html ⇒ Object
213 214 215 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 213 def inner_html get_property(:innerHTML) end |
#open_document_by(&block) ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 240 def open_document_by(&block) open_documents = @driver.document_handles block.call new_documents = @driver.document_handles - open_documents raise 'Multiple documents opened' if new_documents.size > 1 Isomorfeus::Puppetmaster::Document.new(@driver, new_documents.first, Isomorfeus::Puppetmaster::Response.new) end |
#parents ⇒ Object
248 249 250 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 248 def parents find_all_xpath('./ancestor::*').reverse end |
#respond_to?(name, include_private = false) ⇒ Boolean
252 253 254 255 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 252 def respond_to?(name, include_private = false) return true if %i[find_by_content find_by_name find_by_type find_by_value].include?(name) super(name, include_private) end |
#within(&block) ⇒ Object
257 258 259 |
# File 'lib/isomorfeus/puppetmaster/node.rb', line 257 def within(&block) instance_exec(&block) end |