capybara-shadowdom 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb7b431c965e4df3df88f3445e71378f5003e3233940c3d5474cf6ea095a1e3b
4
+ data.tar.gz: d1d9c5503a759dfeb0df6e228deb5663e196bdafe794df3f818db12edb95d367
5
+ SHA512:
6
+ metadata.gz: e8a777d31fea0527c62b8310cdad598a140388336f63e5436cc352904aca24fd3f28e363e3c49e010ac3b8f49834e21b7b2ad5808d50167a47c93d71e16a2268
7
+ data.tar.gz: 9b8a007d8263f1df8559887e1fbc3bb58a5e7068a3614cc25feced5a1088038687abf9bcc1b5a51d6d32927220e35ffb6f1100fb1fea41d29d6819c5bd02f1d7
data/Appraisals ADDED
@@ -0,0 +1,25 @@
1
+ appraise "selenium-webdriver-4-1" do
2
+ gem "selenium-webdriver", "~> 4.1.0"
3
+ end
4
+
5
+ appraise "selenium-webdriver-4-0" do
6
+ gem "selenium-webdriver", "~> 4.0.0"
7
+ end
8
+
9
+ appraise "selenium-webdriver-3" do
10
+ gem "selenium-webdriver", "~> 3"
11
+ end
12
+
13
+ appraise "selenium-webdriver-2" do
14
+ gem "selenium-webdriver", "~> 2"
15
+ gem "capybara", "2.18.0"
16
+ gem "rack", "< 2.0.0"
17
+ end
18
+
19
+ appraise "cuprite" do
20
+ gem "cuprite"
21
+ end
22
+
23
+ appraise "apparition" do
24
+ gem "apparition"
25
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0] - 2022-02-17
2
+
3
+ - First release!
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at yuki24@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+ gem "minitest", "~> 5.0"
9
+ gem "webdrivers"
10
+ gem "pry-byebug"
11
+ gem "webrick"
12
+ gem "rexml"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Yuki Nishijima
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Shadow DOM support for Capybara
2
+
3
+ The `capybara-shadowm` gem adds basic support for the [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) to Capybara.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capybara-shadowdom'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capybara-shadowdom
20
+
21
+ ## Usage
22
+
23
+ Given the custom element:
24
+
25
+ ```html
26
+ <awesome-element>
27
+ <!-- #shadow-root start -->
28
+ <span>Hello shadow world!</span>
29
+
30
+ <input type="text" id="user_name">
31
+ <!-- #shadow-root end -->
32
+ </awesome-element>
33
+ ```
34
+
35
+ You will be able to do:
36
+
37
+ ```ruby
38
+ within custom_element.shadow_root do
39
+ # Displays "Hello shadow world!":
40
+ puts page.text
41
+
42
+ # Asserts the text within the element:
43
+ assert_text "Hello shadow world!"
44
+
45
+ # Input elements within the shadow DOM will also be accessible:
46
+ fill_in "#user_name", with: "awesome@example.org"
47
+ end
48
+ ```
49
+
50
+ ## Browser Support
51
+
52
+ * **Supported Selenium versions**: 3.0 and above
53
+ * **Supported Ruby versions**: 2.7 and above
54
+
55
+ ### Supported drivers:
56
+
57
+ | Driver | Browser | Support | Description |
58
+ | :--- | :---- | :---: | :--- |
59
+ | Selenium | IE11 | N/A | Shadow DOM is not supported. |
60
+ | Selenium | Edge | ✅ | |
61
+ | Selenium | Firefox | ❌ | Fails with `Cyclic object value`. |
62
+ | Selenium | Chrome | ✅ | |
63
+ | Selenium | Safari | ✅ | |
64
+ | [`cuprite` ](https://github.com/rubycdp/cuprite) | Embedded Chromium | ✅ | |
65
+ | [`apparition`](https://github.com/twalpole/apparition) | Embedded Chromium | ❌ | `shadowRoot` node can not be retrieved. |
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
70
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
73
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
74
+ push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yuki24/capybara-shadowdom. This project
79
+ is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
80
+ [code of conduct](https://github.com/yuki24/capybara-shadowdom/blob/master/CODE_OF_CONDUCT.md).
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
85
+
86
+ ## Code of Conduct
87
+
88
+ Everyone interacting in the Capybara::Shadowdom project's codebases, issue trackers, chat rooms and mailing lists
89
+ is expected to follow the
90
+ [code of conduct](https://github.com/yuki24/capybara-shadowdom/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "capybara/shadowdom"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/capybara/shadow_dom/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capybara-shadowdom"
7
+ spec.version = Capybara::ShadowDOM::VERSION
8
+ spec.authors = ["Yuki Nishijima"]
9
+ spec.email = ["yuki24@hey.com"]
10
+
11
+ spec.summary = "Shadow DOM support for Capybara"
12
+ spec.description = "Test Web Components built with the Shadow DOM"
13
+ spec.homepage = "https://github.com/yuki24/capybara-shadowdom"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:test)/|\.(?:git)|appveyor)})
24
+ end
25
+ end
26
+
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "capybara"
32
+ spec.add_development_dependency "appraisal"
33
+ end
data/docs/index.html ADDED
@@ -0,0 +1,104 @@
1
+ <html>
2
+ <head>
3
+ <title>
4
+ Capybara ShadowDOM Test
5
+ </title>
6
+ <meta name="viewport" content="width=device-width,initial-scale=1">
7
+
8
+ <style>
9
+ body {
10
+ font-family: var(--sl-font-sans);
11
+ font-size: var(--sl-font-size-medium);
12
+ font-weight: var(--sl-font-weight-normal);
13
+ letter-spacing: var(--sl-letter-spacing-normal);
14
+ color: var(--sl-color-gray-800);
15
+ line-height: var(--sl-line-height-normal);
16
+ }
17
+
18
+ sl-form div, sl-turbo-form div {
19
+ margin-bottom: 2em;
20
+ }
21
+ </style>
22
+
23
+ <link rel="stylesheet"
24
+ href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.55/dist/themes/light.css">
25
+ <script type="module"
26
+ src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.0.0-beta.55/dist/shoelace.js"></script>
27
+ </head>
28
+
29
+ <body>
30
+ <div style="width: 950px; margin: auto">
31
+ <sl-form class="new_user" id="new_user" action="/hotwire_forms" accept-charset="UTF-8" method="post">
32
+ <div>
33
+ <sl-input label="Name" type="text" name="user[name]" id="user_name" size="medium"></sl-input>
34
+ </div>
35
+
36
+ <div>
37
+ <sl-color-picker name="user[color]" id="user_color"></sl-color-picker>
38
+ </div>
39
+
40
+ <div>
41
+ <sl-range min="0" max="100" step="1" name="user[score]" id="user_score"></sl-range>
42
+ </div>
43
+
44
+ <div>
45
+ <sl-radio-group label="Current city">
46
+ <sl-radio value="tokyo" name="user[current_city]" id="user_current_city_tokyo">Tokyo</sl-radio>
47
+ <sl-radio value="new_york" name="user[current_city]" id="user_current_city_new_york">New York</sl-radio>
48
+ <sl-radio value="london" name="user[current_city]" id="user_current_city_london">London</sl-radio>
49
+ </sl-radio-group>
50
+ </div>
51
+
52
+ <div>
53
+ <sl-select placeholder="Select one" name="user[previous_city]" id="user_previous_city">
54
+ <sl-menu-item value="tokyo" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="0">Tokyo
55
+ </sl-menu-item>
56
+ <sl-menu-item value="new_york" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="-1">New
57
+ York
58
+ </sl-menu-item>
59
+ <sl-menu-item value="london" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="-1">
60
+ London
61
+ </sl-menu-item>
62
+ </sl-select>
63
+ </div>
64
+
65
+ <div>
66
+ <sl-select placeholder="Select two or more" multiple="" clearable="true" name="user[past_cities][]" id="user_past_cities">
67
+ <sl-menu-item value="tokyo" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="0">
68
+ Tokyo
69
+ </sl-menu-item>
70
+ <sl-menu-item value="new_york" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="-1">
71
+ New York
72
+ </sl-menu-item>
73
+ <sl-menu-item value="london" aria-disabled="false" aria-checked="false" role="menuitem" tabindex="-1">
74
+ London
75
+ </sl-menu-item>
76
+ </sl-select>
77
+ </div>
78
+
79
+ <div>
80
+ <sl-checkbox value="1" name="user[remember_me]" id="user_remember_me">
81
+ Remember me
82
+ </sl-checkbox>
83
+ </div>
84
+
85
+ <div>
86
+ <sl-switch value="1" name="user[subscribe_to_emails]" id="user_subscribe_to_emails">
87
+ Subscribe to emails
88
+ </sl-switch>
89
+ </div>
90
+
91
+ <div>
92
+ <sl-textarea resize="auto" name="user[description]" id="user_description" size="medium"></sl-textarea>
93
+ </div>
94
+
95
+ <sl-button submit="" type="primary" data-disable-with="Create User" size="medium">
96
+ Create User
97
+ </sl-button>
98
+ <sl-button submit="" type="primary" data-turbo="false" data-disable-with="Submit without Turbo" size="medium">
99
+ Submit without Turbo
100
+ </sl-button>
101
+ </sl-form>
102
+ </div>
103
+ </body>
104
+ </html>
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "apparition"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "cuprite"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "selenium-webdriver", "~> 2"
12
+ gem "capybara", "2.18.0"
13
+ gem "rack", "< 2.0.0"
14
+
15
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "selenium-webdriver", "~> 3"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "selenium-webdriver", "~> 4.0.0"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake", "~> 13.0"
6
+ gem "minitest", "~> 5.0"
7
+ gem "webdrivers"
8
+ gem "pry-byebug"
9
+ gem "webrick"
10
+ gem "rexml"
11
+ gem "selenium-webdriver", "~> 4.1.0"
12
+
13
+ gemspec path: "../"
@@ -0,0 +1,25 @@
1
+ require 'capybara/node/element'
2
+
3
+ class Capybara::Node::ShadowRoot < Capybara::Node::Element
4
+ def host
5
+ evaluate_script("this.host")
6
+ end
7
+
8
+ def text(type = nil, normalize_ws: false)
9
+ case base.class.to_s
10
+ when "Capybara::Selenium::SafariNode", "Capybara::Cuprite::Node"
11
+ all("*")
12
+ .select { |node| node.send(:parent).nil? }
13
+ .map { |node| node.text(type, normalize_ws: normalize_ws) }
14
+ .join
15
+ else # For Selenium + Chrome and Selenium + Edge:
16
+ all("*")
17
+ .map { |node| node.text(type, normalize_ws: normalize_ws) }
18
+ .join
19
+ end
20
+ end
21
+
22
+ def tag_name
23
+ host.tag_name
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capybara
4
+ module ShadowDOM
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "node/shadow_root"
4
+ require_relative "shadow_dom/version"
5
+
6
+ module Capybara
7
+ module ShadowDOM
8
+ ROOT_KEY = "shadow-6066-11e4-a52e-4f735466cecf"
9
+
10
+ # Adds a way to retrieve the shadow root object of an element. For example, given the HTML below:
11
+ #
12
+ # <awesome-element>
13
+ # <!-- #shadow-root start -->
14
+ # <span>Hello shadow world!</span>
15
+ #
16
+ # <input type="text" id="user_name">
17
+ # <!-- #shadow-root end -->
18
+ # </awesome-element>
19
+ #
20
+ # Then You will be able to do:
21
+ #
22
+ # within custom_element.shadow_root do
23
+ # # Displays "Hello shadow world!":
24
+ # puts page.text
25
+ #
26
+ # # Asserts the text within the element:
27
+ # assert_text "Hello shadow world!"
28
+ #
29
+ # # Input elements within the shadow DOM will also be accessible:
30
+ # fill_in "#user_name", with: "awesome@example.org"
31
+ # end
32
+ #
33
+ def shadow_root
34
+ root_node = evaluate_script("this.shadowRoot")
35
+
36
+ return if root_node.nil?
37
+
38
+ node = if defined?(::Selenium::WebDriver::ShadowRoot) && root_node.is_a?(::Selenium::WebDriver::ShadowRoot)
39
+ # Selenium >= 4.1.x
40
+ driver.send(:build_node, root_node)
41
+ elsif root_node.is_a?(Hash)
42
+ bridge = session.driver.browser.send(:bridge)
43
+
44
+ shadow_key = if defined?(::Selenium::WebDriver::ShadowRoot)
45
+ # Selenium ~> 4.0.x
46
+ ::Selenium::WebDriver::ShadowRoot::ROOT_KEY
47
+ else
48
+ # Selenium ~> 3.x
49
+ ROOT_KEY
50
+ end
51
+
52
+ element = ::Selenium::WebDriver::Element.new(bridge, root_node[shadow_key])
53
+
54
+ session.driver.send(:build_node, element)
55
+ elsif root_node.is_a?(::Capybara::Node::Element)
56
+ root_node.base
57
+ end
58
+
59
+ ::Capybara::Node::ShadowRoot.new(session, node, node, nil)
60
+ end
61
+ end
62
+ end
63
+
64
+ ::Capybara::Node::Element.include(::Capybara::ShadowDOM)
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-shadowdom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Nishijima
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Test Web Components built with the Shadow DOM
42
+ email:
43
+ - yuki24@hey.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Appraisals
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - capybara-shadowdom.gemspec
58
+ - docs/index.html
59
+ - gemfiles/apparition.gemfile
60
+ - gemfiles/cuprite.gemfile
61
+ - gemfiles/selenium_webdriver_2.gemfile
62
+ - gemfiles/selenium_webdriver_3.gemfile
63
+ - gemfiles/selenium_webdriver_4_0.gemfile
64
+ - gemfiles/selenium_webdriver_4_1.gemfile
65
+ - lib/capybara/node/shadow_root.rb
66
+ - lib/capybara/shadow_dom/version.rb
67
+ - lib/capybara/shadowdom.rb
68
+ homepage: https://github.com/yuki24/capybara-shadowdom
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/yuki24/capybara-shadowdom
73
+ source_code_uri: https://github.com/yuki24/capybara-shadowdom
74
+ changelog_uri: https://github.com/yuki24/capybara-shadowdom/blob/main/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.4.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.3.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Shadow DOM support for Capybara
94
+ test_files: []