class Capybara::Apparition::DevToolsProtocol::RemoteObject
Attributes
params[R]
Public Class Methods
new(page, params)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 8 def initialize(page, params) @params = params @page = page end
Public Instance Methods
value()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 13 def value cyclic_checked_value({}) end
Protected Instance Methods
cyclic_checked_value(object_cache)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 19 def cyclic_checked_value(object_cache) if object? if array? extract_properties_array(get_remote_object(id), object_cache) elsif node? params elsif date? res = get_date_string(id) DateTime.parse(res) elsif window_class? { object_id: id } elsif validity_state? extract_properties_object(get_remote_object(id, false), object_cache) elsif object_class? || css_style? || classname? extract_properties_object(get_remote_object(id), object_cache) else params['value'] end else params['value'] end end
Private Instance Methods
array?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 45 def array?; subtype == 'array' end
classname()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 57 def classname; params['className'] end
classname?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 52 def classname?; !classname.nil? end
css_style?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 49 def css_style?; classname == 'CSSStyleDeclaration' end
date?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 46 def date?; subtype == 'date' end
extract_properties_array(properties, object_cache)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 59 def extract_properties_array(properties, object_cache) properties.reject { |prop| prop['name'] == 'apparitionId' } .each_with_object([]) do |property, ary| # TODO: We may need to release these objects next unless property['enumerable'] if property.dig('value', 'subtype') == 'node' # performance shortcut ary.push(property['value']) else ary.push(RemoteObject.new(@page, property['value']).cyclic_checked_value(object_cache)) end end end
extract_properties_object(properties, object_cache)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 73 def extract_properties_object(properties, object_cache) apparition_id = properties&.find { |prop| prop['name'] == 'apparitionId' } &.dig('value', 'value') result = if apparition_id return '(cyclic structure)' if object_cache.key?(apparition_id) object_cache[apparition_id] = {} end properties.reject { |prop| prop['name'] == 'apparitionId' } .each_with_object(result || {}) do |property, hsh| # TODO: We may need to release these objects next unless property['enumerable'] hsh[property['name']] = RemoteObject.new(@page, property['value']).cyclic_checked_value(object_cache) end end
get_date_string(id)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 96 def get_date_string(id) @page.command('Runtime.callFunctionOn', functionDeclaration: 'function(){ return this.toUTCString() }', objectId: id, returnByValue: true).dig('result', 'value') end
get_remote_object(id, own_props = true)
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 92 def get_remote_object(id, own_props = true) @page.command('Runtime.getProperties', objectId: id, ownProperties: own_props)['result'] end
id()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 56 def id; params['objectId'] end
node?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 47 def node?; subtype == 'node' end
object?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 44 def object?; type == 'object' end
object_class?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 48 def object_class?; classname == 'Object' end
subtype()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 55 def subtype; params['subtype'] end
type()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 54 def type; params['type'] end
validity_state?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 51 def validity_state?; classname == 'ValidityState' end
window_class?()
click to toggle source
# File lib/capybara/apparition/dev_tools_protocol/remote_object.rb, line 50 def window_class?; classname == 'Window' end