Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/common/shadow_root.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
module Selenium
21
module WebDriver
22
class ShadowRoot
23
ROOT_KEY = 'shadow-6066-11e4-a52e-4f735466cecf'
24
25
include SearchContext
26
27
#
28
# Creates a new shadow root
29
#
30
# @api private
31
#
32
33
def initialize(bridge, id)
34
@bridge = bridge
35
@id = id
36
end
37
38
def inspect
39
format '#<%<class>s:0x%<hash>x id=%<id>s>', class: self.class, hash: hash * 2, id: @id.inspect
40
end
41
42
def ==(other)
43
other.is_a?(self.class) && ref == other.ref
44
end
45
alias eql? ==
46
47
def hash
48
[@id, @bridge].hash
49
end
50
51
#
52
# @api private
53
# @see SearchContext
54
#
55
56
def ref
57
[:shadow_root, @id]
58
end
59
60
#
61
# Convert to a ShadowRoot JSON Object for transmission over the wire.
62
# @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#basic-terms-and-concepts
63
#
64
# @api private
65
#
66
67
def to_json(*)
68
JSON.generate as_json
69
end
70
71
#
72
# For Rails 3 - http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/
73
#
74
# @api private
75
#
76
77
def as_json(*)
78
{ROOT_KEY => @id}
79
end
80
81
private
82
83
attr_reader :bridge
84
end # ShadowRoot
85
end # WebDriver
86
end # Selenium
87
88