skimming the capybara code for fun because what else is there to do these days
What jumps out at me?
Capybara itself is a fairly small codebase! cloc says 253 .rb
Very small gemfile, nice
Lots of # rubocop:disable (87 matches in 47 files) but such is the library code life
Also I fully support arguing w/ rubocop at all times
Capybara itself is a fairly small codebase! cloc says 253 .rb
Very small gemfile, nice
Lots of # rubocop:disable (87 matches in 47 files) but such is the library code life
Also I fully support arguing w/ rubocop at all times
# appveyor.yml
allow_failures:
- CAPYBARA_IE: true
- CAPYBARA_EDGE: true
lolllll fair enough
skip "Safari doesn& #39;t support multiple sessions" if safari?(session)
TIL
I use capybara to avoid sleep() and their tests have sleep
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Gesicht mit FreudentrĂ€nen" aria-label="Emoji: Gesicht mit FreudentrĂ€nen"> (legit)
allow_failures:
- CAPYBARA_IE: true
- CAPYBARA_EDGE: true
lolllll fair enough
skip "Safari doesn& #39;t support multiple sessions" if safari?(session)
TIL
I use capybara to avoid sleep() and their tests have sleep
it & #39;should bind to the specified host& #39; do
# TODO: travis with jruby in container mode has an issue with this test
skip "safaridriver doesn& #39;t provide a way to set the download directory"
capybara/spec/selenium_spec_ie.rb what... happened here
# TODO: travis with jruby in container mode has an issue with this test
skip "safaridriver doesn& #39;t provide a way to set the download directory"
capybara/spec/selenium_spec_ie.rb what... happened here
it & #39; #right_click should allow modifiers& #39; do
# pending "Actions API doesn& #39;t appear to work for this"
skip & #39;Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358
skip">https://bugzilla.mozilla.org/show_bug.... & #39;Hangs in 69 <= FF < 71 - Dont know what issue for this - previous issue was closed as fixed
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Gesicht mit FreudentrĂ€nen" aria-label="Emoji: Gesicht mit FreudentrĂ€nen">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ±" title="Vor Angst schreiendes Gesicht" aria-label="Emoji: Vor Angst schreiendes Gesicht">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Gesicht mit FreudentrĂ€nen" aria-label="Emoji: Gesicht mit FreudentrĂ€nen">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Laut schreiendes Gesicht" aria-label="Emoji: Laut schreiendes Gesicht">
# pending "Actions API doesn& #39;t appear to work for this"
skip & #39;Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358
skip">https://bugzilla.mozilla.org/show_bug.... & #39;Hangs in 69 <= FF < 71 - Dont know what issue for this - previous issue was closed as fixed
this is the sausage getting MADE folks
this reminds me, I need to do a read-thru of react native soon, I commend my soul to any god who will take it?
# FF doesn& #39;t currently support datetime-local so this is really just a text input
xpath is glory (see next)
this reminds me, I need to do a read-thru of react native soon, I commend my soul to any god who will take it?
# FF doesn& #39;t currently support datetime-local so this is really just a text input
xpath is glory (see next)
link_or_button: ".//a[./ @href] | .//input[./ @type = & #39;submit& #39; or ./ @type = & #39;reset& #39; or ./ @type = & #39;image& #39; or ./ @type = & #39;button& #39;] | .//button",
Oh hey there& #39;s a spec for https://saucelabs.com/
rspec
">https://saucelabs.com/">... # This reads terribly, but must call #within
expect(find(:css, & #39;span.number& #39;).text.to_i).to within(1).of(41)
# This test is for a bug in jruby where `super` isn& #39;t defined correctly
rspec
">https://saucelabs.com/">... # This reads terribly, but must call #within
expect(find(:css, & #39;span.number& #39;).text.to_i).to within(1).of(41)
# This test is for a bug in jruby where `super` isn& #39;t defined correctly
# This test is for a bug in jruby where `super` isn& #39;t defined correctly - https://github.com/jruby/jruby/issues/4678
">https://github.com/jruby/jru... # Reported in https://github.com/teamcapybara/capybara/issues/2115
skip">https://github.com/teamcapyb... & #39;JRuby has an issue with lazy enumerator evaluation& #39; if jruby_lazy_enumerator_workaround?
">https://github.com/jruby/jru... # Reported in https://github.com/teamcapybara/capybara/issues/2115
skip">https://github.com/teamcapyb... & #39;JRuby has an issue with lazy enumerator evaluation& #39; if jruby_lazy_enumerator_workaround?
there is usage of https://github.com/rubys/nokogumbo ">https://github.com/rubys/nok... which is new to my ken "a Nokogiri interface to the Gumbo HTML5 parser"
now THAT is a test (group) name y& #39;all
describe & #39;threadsafe& #39; do
the minitest tests are much shorter than the rspec tests, I feel like this is implicit commentary
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Gesicht mit FreudentrĂ€nen" aria-label="Emoji: Gesicht mit FreudentrĂ€nen">
now THAT is a test (group) name y& #39;all
describe & #39;threadsafe& #39; do
the minitest tests are much shorter than the rspec tests, I feel like this is implicit commentary
oh wait no, that was minitest_spec_spec, now I am in minitest_spec
TIL
pending "Nokogiri doesn& #39;t support case insensitive CSS attribute matchers"
meep?
fscenario & #39;scenario should have focused meta tag& #39; do |example|
TIL
pending "Nokogiri doesn& #39;t support case insensitive CSS attribute matchers"
meep?
fscenario & #39;scenario should have focused meta tag& #39; do |example|
having a test as a test fixture tickles me
# The {Window} class represents a browser window.
# Addressable parsing is more lenient than URI
# { #h_note_10">https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html #h_note_10">https://dvcs.w3.org/hg/webdri... as order of windows isn& #39;t defined in some drivers}.
if RUBY_VERSION >= & #39;2.7& #39;
# The {Window} class represents a browser window.
# Addressable parsing is more lenient than URI
# { #h_note_10">https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html #h_note_10">https://dvcs.w3.org/hg/webdri... as order of windows isn& #39;t defined in some drivers}.
if RUBY_VERSION >= & #39;2.7& #39;
# Workaround issue where some platforms (mac, ???) when passed a host
# of & #39;0.0.0.0& #39; will return a port that is only available on one of the
# ip addresses that resolves to, but the next binding to that port requires
# that port to be available on all ips
# of & #39;0.0.0.0& #39; will return a port that is only available on one of the
# ip addresses that resolves to, but the next binding to that port requires
# that port to be available on all ips
# idx.max is broken with beginless ranges
JRuby < 9.2.8.0 has an issue with lazy enumerators which causes a concurrency issue with network requests here https://github.com/jruby/jruby/issues/4212
#">https://github.com/jruby/jru... RUBY 2.6 will send an empty hash rather than nothing with **options so fix that
JRuby < 9.2.8.0 has an issue with lazy enumerators which causes a concurrency issue with network requests here https://github.com/jruby/jruby/issues/4212
#">https://github.com/jruby/jru... RUBY 2.6 will send an empty hash rather than nothing with **options so fix that
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end
# Workaround for emulating `warn & #39;...& #39;, uplevel: n` in Ruby 2.5 or lower.
This file uses `sleep` to sync up parts of the tests ... tests using Capybara [should use] assertions with builtin waiting behavior.
# Workaround for emulating `warn & #39;...& #39;, uplevel: n` in Ruby 2.5 or lower.
This file uses `sleep` to sync up parts of the tests ... tests using Capybara [should use] assertions with builtin waiting behavior.
IIFE! https://developer.mozilla.org/en-US/docs/Glossary/IIFE">https://developer.mozilla.org/en-US/doc...
I am very impressed with the tests
They are small, elegant, and thourough
I am learning a lot about how to use this thing by reading it, which I had not assumed would be the case
expect( @element).to match_css(& #39;span& #39;) { |el| el[:class] == & #39;number& #39; }
They are small, elegant, and thourough
I am learning a lot about how to use this thing by reading it, which I had not assumed would be the case
expect( @element).to match_css(& #39;span& #39;) { |el| el[:class] == & #39;number& #39; }
@extended_app = extra_middleware.inject( @app) do |ex_app, klass|
if env[& #39;PATH_INFO& #39;] == & #39;/__identify__& #39;
rescue *@server_errors => e
{ use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
<script defer>(typeof jQuery !== & #39;undefined& #39;) && ( http://jQuery.fx.off"> http://jQuery.fx.off = true);</sc
if env[& #39;PATH_INFO& #39;] == & #39;/__identify__& #39;
rescue *@server_errors => e
{ use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
<script defer>(typeof jQuery !== & #39;undefined& #39;) && ( http://jQuery.fx.off"> http://jQuery.fx.off = true);</sc
# Selenium specific implementation of the Capybara::Driver::Node API
gsub ... .tr("\u00a0", & #39; & #39;)
raise NotImplementedError, & #39;Out of browser drop emulation is not implemented for the current browser& #39;
# Clear field by sending the correct number of backspace keys.
gsub ... .tr("\u00a0", & #39; & #39;)
raise NotImplementedError, & #39;Out of browser drop emulation is not implemented for the current browser& #39;
# Clear field by sending the correct number of backspace keys.
# TODO: this would be better if locale can be detected and correct keystrokes sent
driver.execute_script(<<-JS, self, value)
The action api has a speed problem but both chrome and firefox 58 raise errors if we use the faster direct send_keys.
driver.execute_script(<<-JS, self, value)
The action api has a speed problem but both chrome and firefox 58 raise errors if we use the faster direct send_keys.
(feel free to mute, I think I& #39;m not quite halfway through)
# Only trigger a navigation if we haven& #39;t done it already, otherwise it can trigger an endless series of unload modals
::Selenium::WebDriver::Interactions::Pause.prepend PauseDurationFix
# Only trigger a navigation if we haven& #39;t done it already, otherwise it can trigger an endless series of unload modals
::Selenium::WebDriver::Interactions::Pause.prepend PauseDurationFix
^ that my friends is known as a monkey-patch I believe
LOG_MSG = <<~MSG
Chromedriver 75+ defaults to W3C mode. Please upgrade to chromedriver >= \
75.0.3770.90 if you need to access logs while in W3C compliant mode.
LOG_MSG = <<~MSG
Chromedriver 75+ defaults to W3C mode. Please upgrade to chromedriver >= \
75.0.3770.90 if you need to access logs while in W3C compliant mode.
what... are atoms
::Selenium::WebDriver::Remote::Bridge.prepend CapybaraAtoms unless ENV[& #39;DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS& #39;]
capybara/lib/capybara/selenium/nodes/safari_node.rb seems to be... in progress
whilst ie_node.rb is just... very short
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Gesicht mit FreudentrĂ€nen" aria-label="Emoji: Gesicht mit FreudentrĂ€nen">
::Selenium::WebDriver::Remote::Bridge.prepend CapybaraAtoms unless ENV[& #39;DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS& #39;]
capybara/lib/capybara/selenium/nodes/safari_node.rb seems to be... in progress
whilst ie_node.rb is just... very short
# Firefox/marionette has an issue clicking with offset near viewport edge. scroll element to middle just in case
when String
# https://bugzilla.mozilla.org/show_bug.cgi?id=1405370
#">https://bugzilla.mozilla.org/show_bug.... In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and alread
when String
# https://bugzilla.mozilla.org/show_bug.cgi?id=1405370
#">https://bugzilla.mozilla.org/show_bug.... In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and alread
# W3C Chrome/chromedriver < 77 doesn& #39;t maintain mouse button state across actions API performs https://bugs.chromium.org/p/chromedriver/issues/detail?id=2981
there">https://bugs.chromium.org/p/chromed... is a FIFO implementation here
LEGACY_DRAG_CHECK = <<~JS
// fire 2 dragover events to simulate dragging with a direction
@@is_displayed_atom ||= begin
there">https://bugs.chromium.org/p/chromed... is a FIFO implementation here
LEGACY_DRAG_CHECK = <<~JS
// fire 2 dragover events to simulate dragging with a direction
@@is_displayed_atom ||= begin
# safaridriver/safari has an issue where switch_to_frame(:parent) behaves like switch_to_frame(:top)
# iedriverserver has an issue if the current frame is removed from within it
# so we have to move to the default_content and iterate back through the frames
# iedriverserver has an issue if the current frame is removed from within it
# so we have to move to the default_content and iterate back through the frames
# Firefox 68 hangs if we try to switch windows while a modal is visible
# Chromedriver doesn& #39;t wait long enough for state to change when coming out of fullscreen
where is your "Comments are always an apology" now, kid?
# Chromedriver doesn& #39;t wait long enough for state to change when coming out of fullscreen
where is your "Comments are always an apology" now, kid?
# Edgedriver crashes if attempt to clear storage on about:blank
aha, RegexpDisassembler
# delete_if is documented to modify the array after every block iteration - this doesn& #39;t appear to be true
y& #39;all I feel like I& #39;m getting older and wiser *rapidly* in here
aha, RegexpDisassembler
# delete_if is documented to modify the array after every block iteration - this doesn& #39;t appear to be true
y& #39;all I feel like I& #39;m getting older and wiser *rapidly* in here
Capybara::Helpers.warn "DEPRECATED: Passing a symbol (#{css.inspect}) as the CSS locator is deprecated - please pass a string instead
( http://value.is"> http://value.is _a?(Regexp) ? value.match?(val) : val == http://value.to"> http://value.to _s).tap do |res|
this is what peak perf looks like (meme
( http://value.is"> http://value.is _a?(Regexp) ? value.match?(val) : val == http://value.to"> http://value.to _s).tap do |res|
this is what peak perf looks like (meme
else
cls = Array(classes).group_by { |cl| cl.match?(/^!(?!!!)/) }
[(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl.sub(/^!!/, & #39;& #39;))}" } +
cls[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..-1))})" }).join]
cls = Array(classes).group_by { |cl| cl.match?(/^!(?!!!)/) }
[(cls[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl.sub(/^!!/, & #39;& #39;))}" } +
cls[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..-1))})" }).join]
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
">https://bugs.chromium.org/p/chromed... opts.args << & #39;--disable-site-isolation-trials& #39;
The RackTest driver does not support click options
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
">https://bugs.chromium.org/p/chromed... opts.args << & #39;--disable-site-isolation-trials& #39;
The RackTest driver does not support click options
um rack wat
def request_method
/post/i.match?(self[:method] || & #39;& #39;) ? :post : :get
VALID_KEYS = SPATIAL_KEYS + COUNT_KEYS +
vis = case visible
...
vis && case obscured
def distance_segment_segment(l1p1, l1p2, l2p1, l2p2)
# See http://geomalgorithms.com/a07-_distance.html">https://geomalgorithms.com/a07-_dist...
def request_method
/post/i.match?(self[:method] || & #39;& #39;) ? :post : :get
VALID_KEYS = SPATIAL_KEYS + COUNT_KEYS +
vis = case visible
...
vis && case obscured
def distance_segment_segment(l1p1, l1p2, l2p1, l2p2)
# See http://geomalgorithms.com/a07-_distance.html">https://geomalgorithms.com/a07-_dist...
# A {Capybara::Node::Simple} ... is useful in that it does not require a session, an application or a driver, but can still use Capybara& #39;s finders and matchers on any string that contains HTML
# This method is Capybara& #39;s primary defence against asynchronicity problems. It works by attempting to run a given block of code until it succeeds.
rescue ::Capybara::NotSupportedByDriverError
# Implement for drivers that don& #39;t support JS
rescue ::Capybara::NotSupportedByDriverError
# Implement for drivers that don& #39;t support JS
# This currently doesn& #39;t work for Ruby 2.8 due to Minitest not forwarding keyword args separately
# Execute the block, and then accept the modal opened.
gem & #39;pkg-config& #39; # needed by nokogiri
there are Cucumber tests in here!
# Execute the block, and then accept the modal opened.
gem & #39;pkg-config& #39; # needed by nokogiri
there are Cucumber tests in here!
ooh, nice .github/lock.yml
Seems like a good idea for big projects
Well in summary, capybara is cool and fancy and I don& #39;t understand most of it, but now I know more about what it& #39;s made of and how to use it and a whole bunch of weird browser issues
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đ" title="Funkelndes Herz" aria-label="Emoji: Funkelndes Herz">
--fin--
Seems like a good idea for big projects
Well in summary, capybara is cool and fancy and I don& #39;t understand most of it, but now I know more about what it& #39;s made of and how to use it and a whole bunch of weird browser issues
--fin--