mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Detect shadow dom elements when calling path
This commit is contained in:
parent
f43b6499ec
commit
2ec2a2f295
6 changed files with 23 additions and 2 deletions
|
@ -493,6 +493,9 @@ private
|
||||||
var xpath = '';
|
var xpath = '';
|
||||||
var pos, tempitem2;
|
var pos, tempitem2;
|
||||||
|
|
||||||
|
if (el.getRootNode && el.getRootNode() instanceof ShadowRoot) {
|
||||||
|
return ": Shadow DOM element - no XPath :"
|
||||||
|
};
|
||||||
while(el !== xml.documentElement) {
|
while(el !== xml.documentElement) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
tempitem2 = el;
|
tempitem2 = el;
|
||||||
|
|
|
@ -271,5 +271,10 @@ $(function() {
|
||||||
});
|
});
|
||||||
$('#multiple-file, #hidden_file').change(function(e){
|
$('#multiple-file, #hidden_file').change(function(e){
|
||||||
$('body').append($('<p class="file_change">File input changed</p>'));
|
$('body').append($('<p class="file_change">File input changed</p>'));
|
||||||
})
|
});
|
||||||
|
|
||||||
|
var shadow = document.querySelector('#shadow').attachShadow({mode: 'open'});
|
||||||
|
var span = document.createElement('span');
|
||||||
|
span.textContent = 'The things we do in the shadows';
|
||||||
|
shadow.appendChild(span);
|
||||||
});
|
});
|
||||||
|
|
|
@ -409,6 +409,17 @@ Capybara::SpecHelper.spec 'node' do
|
||||||
element = @session.find(:link, 'Second Link')
|
element = @session.find(:link, 'Second Link')
|
||||||
expect(@session.find(:xpath, element.path)).to eq(element)
|
expect(@session.find(:xpath, element.path)).to eq(element)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'reports when element in shadow dom', requires: [:shadow_dom] do
|
||||||
|
@session.visit('/with_js')
|
||||||
|
shadow = @session.find(:css, '#shadow')
|
||||||
|
element = @session.evaluate_script(<<~JS, shadow)
|
||||||
|
(function(root){
|
||||||
|
return root.shadowRoot.querySelector('span');
|
||||||
|
})(arguments[0])
|
||||||
|
JS
|
||||||
|
expect(element.path).to eq ": Shadow DOM element - no XPath :"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#trigger', requires: %i[js trigger] do
|
describe '#trigger', requires: %i[js trigger] do
|
||||||
|
|
|
@ -152,6 +152,7 @@
|
||||||
<p>This is an HTML5 draggable element.</p>
|
<p>This is an HTML5 draggable element.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="shadow"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// a javascript comment
|
// a javascript comment
|
||||||
var aVar = 123;
|
var aVar = 123;
|
||||||
|
|
|
@ -8,7 +8,7 @@ class TestClass
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
||||||
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation
|
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation shadow_dom
|
||||||
] do |example|
|
] do |example|
|
||||||
case example.metadata[:full_description]
|
case example.metadata[:full_description]
|
||||||
when /has_css\? should support case insensitive :class and :id options/
|
when /has_css\? should support case insensitive :class and :id options/
|
||||||
|
|
|
@ -27,6 +27,7 @@ skipped_tests = %i[
|
||||||
scroll
|
scroll
|
||||||
spatial
|
spatial
|
||||||
html_validation
|
html_validation
|
||||||
|
shadow_dom
|
||||||
]
|
]
|
||||||
Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
|
Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
|
||||||
case example.metadata[:full_description]
|
case example.metadata[:full_description]
|
||||||
|
|
Loading…
Reference in a new issue