Switch test file to standards mode

Goal
====

Many of the test files were not specifying a doctype. This means they
are operating in quirks mode which behaves differently than standards
mode. Most systems in production use today operate in some sort of
standards mode (most often HTML5).

There is a question on what modes Capybara should support. There is
quirks mode (no doctype), HTML4, HTML5, various XHTML formats (strict,
traditional, frameset). My suggestion is that we don't care about quirks
mode as it is a legacy format. If someone is using that they will need
to live with those consequences. For the other formats I'm going to
assume if it works in HTML5 it will work in the others. When that
assumption is shown to be false a bug can be filed and we can create a
specific test to cover that format for that scenario but I think running
basically every test in every doctype would add more complication to the
test suite than it is worth.

Implementation
==============

In general the idea is just to add the following to all the test HTML:

    <!DOCTYPE html>

This declares it a standardized HTML5 document following standards mode
rather than quirks mode.

Many of the templates not only lack a doctype but also lack other HTML
structure to be a valid HTML file (i.e. not html tag, head tag, body
tag, etc). Basically they are without a layout. I assume this is because
the test does not dependent a valid HTML file. But since we want to
run in standards mode I think we should add a layout to these files.
Rather than add boilerplate layout code to every file I'm instead using
the layout feature of Sinatra. If the template file already has a
doctype then just render it without the standard layout. Otherwise
render it with the standard layout.

There were a few files that indicated a XHTML namespace. Since we are
doing all HTML5 doctypes we do not need a XHTML namespace and therefore
those attributes were removed. I suspect these namespaces attriubtes
were just copy/paste boilerplate. The exception to this is the
`with_namespace.erb` template. This seems to be testing something
related to XHTML namespaces so I left it and instead added a XHTML
Strict doctype.

The `with_title` template I don't think is used since there is an
inline HTML doc on the Sinatra code with the same endpoint. I suspect
that is leftover from an old refactor so removed that file completely.

Test Failures
-------------

With these changes made we ended up with test failures related to scroll
(expected as that is what prompted this work) and frames. I will follow
up with additional commits to correct these failures. They are
currently:

rspec './lib/capybara/spec/spec_helper.rb[1:44:3]' # Capybara::Session selenium_chrome #frame_title should return the title in the main frame
rspec './lib/capybara/spec/spec_helper.rb[1:44:1]' # Capybara::Session selenium_chrome #frame_title should return the title in a frame
rspec './lib/capybara/spec/spec_helper.rb[1:44:2]' # Capybara::Session selenium_chrome #frame_title should return the title in FrameTwo
rspec './lib/capybara/spec/spec_helper.rb[1:98:5]' # Capybara::Session selenium_chrome #scroll_to can scroll the window to the vertical bottom
rspec './lib/capybara/spec/spec_helper.rb[1:98:3]' # Capybara::Session selenium_chrome #scroll_to can scroll an element to the center of the viewport
rspec './lib/capybara/spec/spec_helper.rb[1:98:2]' # Capybara::Session selenium_chrome #scroll_to can scroll an element to the bottom of the viewport
rspec './lib/capybara/spec/spec_helper.rb[1:98:6]' # Capybara::Session selenium_chrome #scroll_to can scroll the window to the vertical center
rspec './lib/capybara/spec/spec_helper.rb[1:98:7]' # Capybara::Session selenium_chrome #scroll_to can scroll the window to specific location
rspec './lib/capybara/spec/spec_helper.rb[1:98:15]' # Capybara::Session selenium_chrome #scroll_to can scroll the window by a specific amount
This commit is contained in:
Eric Anderson 2021-07-22 12:23:20 -04:00
parent 76912ce0e8
commit f20c8de93c
No known key found for this signature in database
GPG Key ID: D580B6A174DFE311
31 changed files with 65 additions and 46 deletions

View File

@ -163,10 +163,17 @@ class TestApp < Sinatra::Base
get '/with_title' do
<<-HTML
<title>#{params[:title] || 'Test Title'}</title>
<body>
<svg><title>abcdefg</title></svg>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>#{params[:title] || 'Test Title'}</title>
</head>
<body>
<svg><title>abcdefg</title></svg>
</body>
</html>
HTML
end
@ -177,7 +184,9 @@ class TestApp < Sinatra::Base
end
get '/:view' do |view|
erb view.to_sym, locals: { referrer: request.referrer }
view_template = "#{__dir__}/views/#{view}.erb"
has_layout = File.exist?(view_template) && File.open(view_template) { |f| f.first.downcase.include?('doctype') }
erb view.to_sym, locals: { referrer: request.referrer }, layout: !has_layout
end
post '/form' do

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@ -46,4 +47,3 @@
<iframe id="frameOne" src="/frame_one"></iframe>
</html>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>This is the child frame title</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>This is the title of frame one</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>This is the parent frame title</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>This is the title of frame two</title>

View File

@ -1,4 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<body>
<div>
Initial alert page

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@ -44,4 +45,3 @@
</div>
</body>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@ -29,4 +30,4 @@
<div id="clicker"></div>
</div>
</body>
</html>
</html>

View File

@ -1,5 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<body>
<div>
<a href="#">First Link</a>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>Title of the first popup</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>Title of popup two</title>

View File

@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react/umd/react.development.js"></script>
@ -42,4 +42,4 @@
document.getElementById('root'));
</script>
</body>
</html>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html style="height: 250%; width: 150%">
<head>
<style>
@ -17,4 +18,4 @@
</div>
</div>
</body>
</html>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
@ -28,4 +29,3 @@
<div class="footer distance">10</div>
</body>
</html>

View File

@ -1,5 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_animation</title>
@ -79,4 +79,3 @@
</a>
</body>
</html>

View File

@ -1,5 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<base href="http://example2.com" />

View File

@ -1,4 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_dragula</title>
@ -21,4 +22,3 @@
</script>
</body>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<style>
@ -14,4 +15,4 @@
<a href="/">Go to root</a>
</div>
<footer>My footer</footer>
</body>
</body>

View File

@ -1,5 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_hover</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

View File

@ -1,5 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_js</title>
@ -160,4 +160,3 @@
</script>
</body>
</html>

View File

@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Namespace</title>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<script>
@ -14,4 +15,4 @@
<body>
<div>This delays unload by 2 seconds</div>
</body>
</html>
</html>

View File

@ -1,4 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_sortable_js</title>
@ -18,4 +19,3 @@
</script>
</body>
</html>

View File

@ -1,5 +0,0 @@
<title>Test Title</title>
<body>
<svg><title>abcdefg</title></svg>
</body>

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<script>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>With Windows</title>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title>With Frames</title>