class Isomorfeus::Puppetmaster::Node
Constants
- SUPPORTED_HTML_AND_SVG_ELEMENTS
- SUPPORTED_HTML_ELEMENTS
- SUPPORTED_SVG_ELEMENTS
www.w3.org/TR/SVG11/eltindex.html elements listed above not mentioned a second time
Attributes
css_selector[R]
document[R]
handle[R]
name[R]
tag[R]
xpath_query[R]
Public Class Methods
new(driver, document, node_data)
click to toggle source
# 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
new_by_tag(driver, document, node_data)
click to toggle source
# 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
Public Instance Methods
==(other)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 137 def ==(other) @driver.node_equal(self, other) end
[](attribute)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 133 def [](attribute) get_attribute(attribute) end
evaluate_ruby(ruby_source = '', &block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 185 def has_content?(content, **options) visible_text.include?(content) end
has_css?(selector, **options)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 189 def has_css?(selector, **options) res = find_all(selector) return false unless res return false if options.has_key?(:count) && options[:count] != res.size return true end
has_text?(text, **options)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 196 def has_text?(text, **options) count = visible_text.scan(/#{text}/).size return false if options.has_key?(:count) && options[:count] != count count > 0 end
has_xpath?(query, **options)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 202 def has_xpath?(query, **options) res = find_all_xpath(query) return false unless res return false if options.has_key?(:count) && options[:count] != res.size return true end
html()
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 209 def html get_property(:outerHTML) end
inner_html()
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 213 def inner_html get_property(:innerHTML) end
method_missing(name, *args)
click to toggle source
Calls superclass method
# 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
open_document_by(&block)
click to toggle source
# 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()
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 248 def parents find_all_xpath('./ancestor::*').reverse end
respond_to?(name, include_private = false)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# File lib/isomorfeus/puppetmaster/node.rb, line 257 def within(&block) instance_exec(&block) end
Protected Instance Methods
compile_ruby_source(source_code)
click to toggle source
assertions
# probably can keep :assert_all_of_selectors, :assert_any_of_selectors, :assert_selector, :assert_text, :assert_no_selector, :assert_none_of_selectors, :assert_no_text, :refute_selector
# File lib/isomorfeus/puppetmaster/node.rb, line 274 def compile_ruby_source(source_code) # TODO maybe use compile server Opal.compile(source_code, parse_comments: false) end