mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
:element selector should ignore XML namespaces
This commit is contained in:
parent
7dc2a703ed
commit
1f51047576
3 changed files with 41 additions and 2 deletions
|
@ -468,7 +468,7 @@ end
|
|||
|
||||
Capybara.add_selector(:element) do
|
||||
xpath do |locator, **|
|
||||
locator ? XPath.descendant(locator.to_sym) : XPath.descendant
|
||||
xp = XPath.descendant.where(locator ? XPath.local_name == locator.to_s : nil)
|
||||
end
|
||||
|
||||
expression_filter(:attributes, matcher: /.+/) do |xpath, name, val|
|
||||
|
|
20
lib/capybara/spec/views/with_html5_svg.erb
Normal file
20
lib/capybara/spec/views/with_html5_svg.erb
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Namespace</title>
|
||||
</head>
|
||||
<body id="body">
|
||||
<div>
|
||||
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid slice"
|
||||
style="width:100%; height:100%; position:absolute; top:0; left:0; z-index:-1;">
|
||||
<linearGradient id="gradient">
|
||||
<stop class="begin" offset="0%"/>
|
||||
<stop class="end" offset="100%"/>
|
||||
</linearGradient>
|
||||
<rect x="0" y="0" width="100" height="100" style="fill:url(#gradient)" />
|
||||
<rect x="150" y="150" width="25" height="25" style="fill:url(#gradient)" />
|
||||
<circle cx="50" cy="50" r="30" style="fill:url(#gradient)" />
|
||||
</svg>
|
||||
<div>
|
||||
</body>
|
||||
</html>
|
|
@ -202,7 +202,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
|
|||
expect(element.path).to eq('/HTML/BODY/DIV[2]/A[1]')
|
||||
end
|
||||
|
||||
it 'handles namespaces' do
|
||||
it 'handles namespaces in xhtml' do
|
||||
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
||||
session.visit '/with_namespace'
|
||||
rect = session.find(:css, 'div svg rect:first-of-type')
|
||||
|
@ -210,6 +210,14 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
|
|||
expect(session.find(:xpath, rect.path)).to eq rect
|
||||
end
|
||||
|
||||
it 'handles default namespaces in html5' do
|
||||
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
||||
session.visit '/with_html5_svg'
|
||||
rect = session.find(:css, 'div svg rect:first-of-type')
|
||||
expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")
|
||||
expect(session.find(:xpath, rect.path)).to eq rect
|
||||
end
|
||||
|
||||
it 'handles case sensitive element names' do
|
||||
pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)
|
||||
session.visit '/with_namespace'
|
||||
|
@ -412,6 +420,17 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ":element selector" do
|
||||
it "can find html5 svg elements" do
|
||||
session.visit('with_html5_svg')
|
||||
expect(session).to have_selector(:element, :svg)
|
||||
expect(session).to have_selector(:element, :rect, visible: true)
|
||||
expect(session).to have_selector(:element, :rect, visible: :hidden)
|
||||
expect(session).to have_selector(:element, :circle)
|
||||
expect(session).to have_selector(:element, :linearGradient, visible: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def headless_or_remote?
|
||||
|
|
Loading…
Reference in a new issue