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
# appveyor.yml
allow_failures:
- CAPYBARA_IE: true
- CAPYBARA_EDGE: true
lolllll fair enough

skip "Safari doesn't support multiple sessions" if safari?(session)
TIL

I use capybara to avoid sleep() and their tests have sleep 😂 (legit)
it 'should bind to the specified host' do
# TODO: travis with jruby in container mode has an issue with this test

skip "safaridriver doesn't provide a way to set the download directory"

capybara/spec/selenium_spec_ie.rb what... happened here
it ' #right_click should allow modifiers' do
# pending "Actions API doesn't appear to work for this"

skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358

skip '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'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 = 'submit' or ./ @type = 'reset' or ./ @type = 'image' or ./ @type = 'button'] | .//button",
Oh hey there's a spec for https://saucelabs.com/ 

rspec
# This reads terribly, but must call #within
expect(find(:css, 'span.number').text.to_i).to within(1).of(41)

# This test is for a bug in jruby where `super` isn't defined correctly
why... are we deconstructing regexes
help
there is usage of https://github.com/rubys/nokogumbo  which is new to my ken "a Nokogiri interface to the Gumbo HTML5 parser"

now THAT is a test (group) name y'all
describe 'threadsafe' 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't support case insensitive CSS attribute matchers"

meep?
fscenario 'scenario should have focused meta tag' 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

# { https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#h_note_10 as order of windows isn't defined in some drivers}.

if RUBY_VERSION >= '2.7'
# Workaround issue where some platforms (mac, ???) when passed a host
# of '0.0.0.0' 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
def monotonic_time; Process.clock_gettime Process::CLOCK_MONOTONIC; end

# Workaround for emulating `warn '...', 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.
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('span') { |el| el[:class] == 'number' }
@extended_app = extra_middleware.inject( @app) do |ex_app, klass|

if env['PATH_INFO'] == '/__identify__'

rescue *@server_errors => e

{ use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }

<script defer>(typeof jQuery !== 'undefined') && ( http://jQuery.fx.off  = true);</sc
# Selenium specific implementation of the Capybara::Driver::Node API

gsub ... .tr("\\u00a0", ' ')

raise NotImplementedError, 'Out of browser drop emulation is not implemented for the current browser'

# 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.
(feel free to mute, I think I'm not quite halfway through)

# Only trigger a navigation if we haven'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.
what... are atoms
::Selenium::WebDriver::Remote::Bridge.prepend CapybaraAtoms unless ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS']

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

# 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't maintain mouse button state across actions API performs https://bugs.chromium.org/p/chromedriver/issues/detail?id=2981

there 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
# Firefox 68 hangs if we try to switch windows while a modal is visible

# Chromedriver doesn'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't appear to be true

y'all I feel like I'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 _a?(Regexp) ? value.match?(val) : val == 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(/^!!/, ''))}" } +
cls[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..-1))})" }).join]
module SpatialSugar

Walpole I salute you
# 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
opts.args << '--disable-site-isolation-trials'

The RackTest driver does not support click options
um rack wat
def request_method
/post/i.match?(self[:method] || '') ? :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
# A {Capybara::Node::Simple} ... is useful in that it does not require a session, an application or a driver, but can still use Capybara's finders and matchers on any string that contains HTML
# This method is Capybara'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't support JS
# This currently doesn't work for Ruby 2.8 due to Minitest not forwarding keyword args separately

# Execute the block, and then accept the modal opened.

gem 'pkg-config' # 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't understand most of it, but now I know more about what it's made of and how to use it and a whole bunch of weird browser issues 💖
--fin--
You can follow @compiledwrong.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: