repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/selector/filters/node_filter.rb | lib/capybara/selector/filters/node_filter.rb | # frozen_string_literal: true
require 'capybara/selector/filters/base'
module Capybara
class Selector
module Filters
class NodeFilter < Base
def initialize(name, matcher, block, **options)
super
@block = if boolean?
proc do |node, value|
error_cnt = er... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/selector/filters/base.rb | lib/capybara/selector/filters/base.rb | # frozen_string_literal: true
module Capybara
class Selector
module Filters
class Base
def initialize(name, matcher, block, **options)
@name = name
@matcher = matcher
@block = block
@options = options
@options[:valid_values] = [true, false] if optio... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/selector/filters/locator_filter.rb | lib/capybara/selector/filters/locator_filter.rb | # frozen_string_literal: true
require 'capybara/selector/filters/base'
module Capybara
class Selector
module Filters
class LocatorFilter < NodeFilter
def initialize(block, **options)
super(nil, nil, block, **options)
end
def matches?(node, value, context = nil, exact:)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/selector/builders/xpath_builder.rb | lib/capybara/selector/builders/xpath_builder.rb | # frozen_string_literal: true
require 'xpath'
module Capybara
class Selector
# @api private
class XPathBuilder
def initialize(expression)
@expression = expression || ''
end
attr_reader :expression
def add_attribute_conditions(**conditions)
@expression = conditions.i... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/selector/builders/css_builder.rb | lib/capybara/selector/builders/css_builder.rb | # frozen_string_literal: true
require 'xpath'
module Capybara
class Selector
# @api private
class CSSBuilder
def initialize(expression)
@expression = expression || ''
end
attr_reader :expression
def add_attribute_conditions(**attributes)
@expression = attributes.inj... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/base_query.rb | lib/capybara/queries/base_query.rb | # frozen_string_literal: true
module Capybara
# @api private
module Queries
class BaseQuery
COUNT_KEYS = %i[count minimum maximum between].freeze
attr_reader :options
attr_writer :session_options
def initialize(options)
@session_options = options.delete(:session_options)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/match_query.rb | lib/capybara/queries/match_query.rb | # frozen_string_literal: true
module Capybara
module Queries
class MatchQuery < Capybara::Queries::SelectorQuery
def visible
options.key?(:visible) ? super : :all
end
private
def assert_valid_keys
invalid_options = @options.keys & COUNT_KEYS
unless invalid_options.... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/sibling_query.rb | lib/capybara/queries/sibling_query.rb | # frozen_string_literal: true
module Capybara
module Queries
class SiblingQuery < SelectorQuery
# @api private
def resolve_for(node, exact = nil)
@sibling_node = node
node.synchronize do
scope = node.respond_to?(:session) ? node.session.current_scope : node.find(:xpath, '/*'... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/ancestor_query.rb | lib/capybara/queries/ancestor_query.rb | # frozen_string_literal: true
module Capybara
module Queries
class AncestorQuery < Capybara::Queries::SelectorQuery
# @api private
def resolve_for(node, exact = nil)
@child_node = node
node.synchronize do
scope = node.respond_to?(:session) ? node.session.current_scope : nod... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/active_element_query.rb | lib/capybara/queries/active_element_query.rb | # frozen_string_literal: true
module Capybara
# @api private
module Queries
class ActiveElementQuery < BaseQuery
def initialize(**options)
@options = options
super(@options)
end
def resolve_for(session)
node = session.driver.active_element
[Capybara::Node::Ele... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/title_query.rb | lib/capybara/queries/title_query.rb | # frozen_string_literal: true
module Capybara
# @api private
module Queries
class TitleQuery < BaseQuery
def initialize(expected_title, **options)
@expected_title = expected_title.is_a?(Regexp) ? expected_title : expected_title.to_s
@options = options
super(@options)
@sear... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/selector_query.rb | lib/capybara/queries/selector_query.rb | # frozen_string_literal: true
require 'matrix'
module Capybara
module Queries
class SelectorQuery < Queries::BaseQuery
attr_reader :expression, :selector, :locator, :options
SPATIAL_KEYS = %i[above below left_of right_of near].freeze
VALID_KEYS = SPATIAL_KEYS + COUNT_KEYS +
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/style_query.rb | lib/capybara/queries/style_query.rb | # frozen_string_literal: true
module Capybara
# @api private
module Queries
class StyleQuery < BaseQuery
def initialize(expected_styles, session_options:, **options)
@expected_styles = stringify_keys(expected_styles)
@options = options
@actual_styles = {}
super(@options)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/text_query.rb | lib/capybara/queries/text_query.rb | # frozen_string_literal: true
module Capybara
# @api private
module Queries
class TextQuery < BaseQuery
def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments
@type = type.nil? ? default_type : type
raise ArgumentError, "#{@type} i... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/queries/current_path_query.rb | lib/capybara/queries/current_path_query.rb | # frozen_string_literal: true
require 'addressable/uri'
module Capybara
# @api private
module Queries
class CurrentPathQuery < BaseQuery
def initialize(expected_path, **options, &optional_filter_block)
super(options)
@expected_path = expected_path
@options = {
url: !@ex... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/session/matchers.rb | lib/capybara/session/matchers.rb | # frozen_string_literal: true
module Capybara
module SessionMatchers
##
# Asserts that the page has the given path.
# By default, if passed a full url this will compare against the full url,
# if passed a path only the path+query portion will be compared, if passed a regexp
# the comparison will ... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/session/config.rb | lib/capybara/session/config.rb | # frozen_string_literal: true
require 'delegate'
module Capybara
class SessionConfig
OPTIONS = %i[always_include_port run_server default_selector default_max_wait_time ignore_hidden_elements
automatic_reload match exact exact_text raise_server_errors visible_text_only
automatic... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/test_app.rb | lib/capybara/spec/test_app.rb | # frozen_string_literal: true
require 'sinatra/base'
require 'tilt/erb'
require 'rack'
require 'yaml'
class TestApp < Sinatra::Base
class TestAppError < Exception; end # rubocop:disable Lint/InheritException
class TestAppOtherError < Exception # rubocop:disable Lint/InheritException
def initialize(string1, m... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/spec_helper.rb | lib/capybara/spec/spec_helper.rb | # frozen_string_literal: true
require 'rspec'
require 'rspec/expectations'
require 'capybara'
require 'capybara/rspec' # Required here instead of in rspec_spec to avoid RSpec deprecation warning
require 'capybara/spec/test_app'
require 'nokogiri'
Capybara.save_path = File.join(Dir.pwd, 'save_path_tmp')
module Capyba... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/select_spec.rb | lib/capybara/spec/session/select_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#select' do
before do
@session.visit('/form')
end
it 'should return value of the first option' do
expect(@session.find_field('Title').value).to eq('Mrs')
end
it 'should return value of the selected option' do
@session.select('Miss', from:... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/find_field_spec.rb | lib/capybara/spec/session/find_field_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#find_field' do
before do
@session.visit('/form')
end
it 'should find any field' do
Capybara.test_id = 'data-test-id'
expect(@session.find_field('Dog').value).to eq('dog')
expect(@session.find_field('form_description').value).to eq('Descri... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/current_scope_spec.rb | lib/capybara/spec/session/current_scope_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#current_scope' do
before do
@session.visit('/with_scope')
end
context 'when not in a #within block' do
it 'should return the document' do
expect(@session.current_scope).to be_a Capybara::Node::Document
end
end
context 'when in a #w... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_selector_spec.rb | lib/capybara/spec/session/assert_selector_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_selector' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selector is on the page' do
@session.assert_selector(:xpath, '//p')
@session.assert_selector(:css, 'p a#foo')
@session.assert_selector("//p[con... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/execute_script_spec.rb | lib/capybara/spec/session/execute_script_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#execute_script', requires: [:js] do
it 'should execute the given script and return nothing' do
@session.visit('/with_js')
expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
expect(@session).... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/find_by_id_spec.rb | lib/capybara/spec/session/find_by_id_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#find_by_id' do
before do
@session.visit('/with_html')
end
it 'should find any element by id' do
expect(@session.find_by_id('red').tag_name).to eq('a')
end
it 'casts to string' do
expect(@session.find_by_id(:red).tag_name).to eq('a')
en... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/click_button_spec.rb | lib/capybara/spec/session/click_button_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#click_button' do
before do
@session.visit('/form')
end
it 'should wait for asynchronous load', requires: [:js] do
@session.visit('/with_js')
@session.using_wait_time(1.5) do
@session.click_link('Click me')
@session.click_button('N... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/find_button_spec.rb | lib/capybara/spec/session/find_button_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#find_button' do
before do
@session.visit('/form')
end
it 'should find any button' do
expect(@session.find_button('med')[:id]).to eq('mediocre')
expect(@session.find_button('crap321').value).to eq('crappy')
end
context 'aria_label attribu... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/evaluate_script_spec.rb | lib/capybara/spec/session/evaluate_script_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#evaluate_script', requires: [:js] do
it 'should evaluate the given script and return whatever it produces' do
@session.visit('/with_js')
expect(@session.evaluate_script('1+3')).to eq(4)
end
it 'should ignore leading whitespace' do
@session.vi... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/find_link_spec.rb | lib/capybara/spec/session/find_link_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#find_link' do
before do
@session.visit('/with_html')
end
it 'should find any link' do
expect(@session.find_link('foo').text).to eq('ullamco')
expect(@session.find_link('labore')[:href]).to match %r{/with_simple_html$}
end
context 'aria_l... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/choose_spec.rb | lib/capybara/spec/session/choose_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#choose' do
before do
@session.visit('/form')
end
it 'should choose a radio button by id' do
@session.choose('gender_male')
@session.click_button('awesome')
expect(extract_results(@session)['gender']).to eq('male')
end
it 'ignores rea... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/text_spec.rb | lib/capybara/spec/session/text_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#text' do
it 'should print the text of the page' do
@session.visit('/with_simple_html')
expect(@session.text).to eq('Bar')
end
it 'ignores invisible text by default' do
@session.visit('/with_html')
expect(@session.find(:id, 'hidden-text').... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/active_element_spec.rb | lib/capybara/spec/session/active_element_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#active_element', requires: [:active_element] do
it 'should return the active element' do
@session.visit('/form')
@session.send_keys(:tab)
expect(@session.active_element).to match_selector(:css, '[tabindex="1"]')
@session.send_keys(:tab)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/first_spec.rb | lib/capybara/spec/session/first_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#first' do
before do
@session.visit('/with_html')
end
it 'should find the first element using the given locator' do
expect(@session.first('//h1').text).to eq('This is a test')
expect(@session.first("//input[@id='test_field']").value).to eq('mo... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/response_code_spec.rb | lib/capybara/spec/session/response_code_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#status_code' do
it 'should return response codes', requires: [:status_code] do
@session.visit('/with_simple_html')
expect(@session.status_code).to eq(200)
end
end
| ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/reset_session_spec.rb | lib/capybara/spec/session/reset_session_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#reset_session!' do
it 'removes cookies from current domain' do
@session.visit('/set_cookie')
@session.visit('/get_cookie')
expect(@session).to have_content('test_cookie')
@session.reset_session!
@session.visit('/get_cookie')
expect(@s... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/attach_file_spec.rb | lib/capybara/spec/session/attach_file_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#attach_file' do
let(:test_file_path) { File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__)) }
let(:another_test_file_path) { File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__)) }
let(:test_jpg_file_path) { File.e... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_all_of_selectors_spec.rb | lib/capybara/spec/session/assert_all_of_selectors_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_all_of_selectors' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selectors are on the page' do
@session.assert_all_of_selectors(:css, 'p a#foo', 'h2#h2one', 'h2#h2two')
end
it 'should be false if any of ... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_selector_spec.rb | lib/capybara/spec/session/has_selector_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_selector?' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selector is on the page' do
expect(@session).to have_selector(:xpath, '//p')
expect(@session).to have_selector(:css, 'p a#foo')
expect(@session).... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_button_spec.rb | lib/capybara/spec/session/has_button_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_button?' do
before do
@session.visit('/form')
end
it 'should be true if the given button is on the page' do
expect(@session).to have_button('med')
expect(@session).to have_button('crap321')
expect(@session).to have_button(:crap321)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/accept_confirm_spec.rb | lib/capybara/spec/session/accept_confirm_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
before do
@session.visit('/with_js')
end
it 'should accept the confirm' do
@session.accept_confirm do
@session.click_link('Open confirm')
end
expect(@session).to have_xpath("//a[@id='open-conf... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_xpath_spec.rb | lib/capybara/spec/session/has_xpath_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_xpath?' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selector is on the page' do
expect(@session).to have_xpath('//p')
expect(@session).to have_xpath("//p//a[@id='foo']")
expect(@session).to have_xpath... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/dismiss_confirm_spec.rb | lib/capybara/spec/session/dismiss_confirm_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
before do
@session.visit('/with_js')
end
it 'should dismiss the confirm' do
@session.dismiss_confirm do
@session.click_link('Open confirm')
end
expect(@session).to have_xpath("//a[@id='open-c... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/all_spec.rb | lib/capybara/spec/session/all_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#all' do
before do
@session.visit('/with_html')
end
it 'should find all elements using the given locator' do
expect(@session.all('//p').size).to eq(3)
expect(@session.all('//h1').first.text).to eq('This is a test')
expect(@session.all("//i... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_current_path_spec.rb | lib/capybara/spec/session/assert_current_path_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_current_path' do
before do
@session.visit('/with_js')
end
it 'should not raise if the page has the given current path' do
expect { @session.assert_current_path('/with_js') }.not_to raise_error
end
it 'should allow regexp matches' do
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/within_spec.rb | lib/capybara/spec/session/within_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#within' do
before do
@session.visit('/with_scope')
end
context 'with CSS selector' do
it 'should click links in the given scope' do
@session.within(:css, '#for_bar li:first-child') do
@session.click_link('Go')
end
expect... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/check_spec.rb | lib/capybara/spec/session/check_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#check' do
before do
@session.visit('/form')
end
describe "'checked' attribute" do
it 'should be true if checked' do
@session.check('Terms of Use')
expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_trut... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/current_url_spec.rb | lib/capybara/spec/session/current_url_spec.rb | # frozen_string_literal: true
require 'capybara/spec/test_app'
Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
before :all do # rubocop:disable RSpec/BeforeAfterAll
@servers = Array.new(2) { Capybara::Server.new(TestApp.new).boot }
# sanity check
expect(@servers[0].port).not_to... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/unselect_spec.rb | lib/capybara/spec/session/unselect_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#unselect' do
before do
@session.visit('/form')
end
context 'with multiple select' do
it 'should unselect an option from a select box by id' do
@session.unselect('Commando', from: 'form_underwear')
@session.click_button('awesome')
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_title_spec.rb | lib/capybara/spec/session/has_title_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_title?' do
before do
@session.visit('/with_js')
end
it 'should be true if the page has the given title' do
expect(@session).to have_title('with_js')
expect(@session.has_title?('with_js')).to be true
end
it 'should allow regexp matche... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_sibling_spec.rb | lib/capybara/spec/session/has_sibling_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#have_sibling' do
before do
@session.visit('/with_html')
end
it 'should assert a prior sibling element using the given locator' do
el = @session.find(:css, '#mid_sibling')
expect(el).to have_sibling(:css, '#pre_sibling')
end
it 'should as... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_field_spec.rb | lib/capybara/spec/session/has_field_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_field' do
before { @session.visit('/form') }
it 'should be true if the field is on the page' do
expect(@session).to have_field('Dog')
expect(@session).to have_field('form_description')
expect(@session).to have_field('Region')
expect(@se... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/evaluate_async_script_spec.rb | lib/capybara/spec/session/evaluate_async_script_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#evaluate_async_script', requires: [:js] do
it 'should evaluate the given script and return whatever it produces' do
@session.visit('/with_js')
expect(@session.evaluate_async_script('arguments[0](4)')).to eq(4)
end
it 'should support passing eleme... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_css_spec.rb | lib/capybara/spec/session/has_css_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_css?' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selector is on the page' do
expect(@session).to have_css('p')
expect(@session).to have_css('p a#foo')
end
it 'should warn when passed a symbol' do
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/scroll_spec.rb | lib/capybara/spec/session/scroll_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
before do
@session.visit('/scroll')
end
it 'can scroll an element to the top of the viewport' do
el = @session.find(:css, '#scroll')
@session.scroll_to(el, align: :top)
expect(el.evaluate_script('this.ge... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/matches_style_spec.rb | lib/capybara/spec/session/matches_style_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do
before do
@session.visit('/with_html')
end
it 'should be true if the element has the given style' do
expect(@session.find(:css, '#first')).to match_style(display: 'block')
expect(@session.find(:css, '#firs... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/go_back_spec.rb | lib/capybara/spec/session/go_back_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#go_back', requires: [:js] do
it 'should fetch a response from the driver from the previous page' do
@session.visit('/')
expect(@session).to have_content('Hello world!')
@session.visit('/foo')
expect(@session).to have_content('Another World')
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/html_spec.rb | lib/capybara/spec/session/html_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/uncheck_spec.rb | lib/capybara/spec/session/uncheck_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#uncheck' do
before do
@session.visit('/form')
end
it 'should uncheck a checkbox by id' do
@session.uncheck('form_pets_hamster')
@session.click_button('awesome')
expect(extract_results(@session)['pets']).to include('dog')
expect(extrac... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/save_and_open_screenshot_spec.rb | lib/capybara/spec/session/save_and_open_screenshot_spec.rb | # frozen_string_literal: true
require 'launchy'
Capybara::SpecHelper.spec '#save_and_open_screenshot' do
before do
@session.visit '/'
end
it 'opens file from the default directory', requires: [:screenshot] do
expected_file_regex = /capybara-\d+\.png/
allow(@session.driver).to receive(:save_screensh... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/fill_in_spec.rb | lib/capybara/spec/session/fill_in_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#fill_in' do
before do
@session.visit('/form')
end
it 'should fill in a text field by id' do
@session.fill_in('form_first_name', with: 'Harry')
@session.click_button('awesome')
expect(extract_results(@session)['first_name']).to eq('Harry')... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_link_spec.rb | lib/capybara/spec/session/has_link_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_link?' do
before do
@session.visit('/with_html')
end
it 'should be true if the given link is on the page' do
expect(@session).to have_link('foo')
expect(@session).to have_link('awesome title')
expect(@session).to have_link('A link', h... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/screenshot_spec.rb | lib/capybara/spec/session/screenshot_spec.rb | # coding: US-ASCII
# frozen_string_literal: true
Capybara::SpecHelper.spec '#save_screenshot' do
let(:image_path) { File.join(Dir.tmpdir, 'capybara-screenshot.png') }
before do
@session.visit '/'
end
it 'should generate PNG file', requires: [:screenshot] do
path = @session.save_screenshot image_path
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_text_spec.rb | lib/capybara/spec/session/has_text_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_text?' do
it 'should be true if the given text is on the page at least once' do
@session.visit('/with_html')
expect(@session).to have_text('est')
expect(@session).to have_text('Lorem')
expect(@session).to have_text('Redirect')
expect(@... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/ancestor_spec.rb | lib/capybara/spec/session/ancestor_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#ancestor' do
before do
@session.visit('/with_html')
end
after do
Capybara::Selector.remove(:monkey)
end
it 'should find the ancestor element using the given locator' do
el = @session.find(:css, '#first_image')
expect(el.ancestor('//p... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/title_spec.rb | lib/capybara/spec/session/title_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#title' do
it 'should get the title of the page' do
@session.visit('/with_title')
expect(@session.title).to eq('Test Title')
end
context 'with css as default selector' do
before { Capybara.default_selector = :css }
after { Capybara.defaul... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/node_wrapper_spec.rb | lib/capybara/spec/session/node_wrapper_spec.rb | # frozen_string_literal: true
class NodeWrapper
def initialize(element); @element = element end
def to_capybara_node(); @element end
end
Capybara::SpecHelper.spec '#to_capybara_node' do
before do
@session.visit('/with_html')
end
it 'should support have_xxx expectations' do
para = NodeWrapper.new(@s... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/headers_spec.rb | lib/capybara/spec/session/headers_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#response_headers' do
it 'should return response headers', requires: [:response_headers] do
@session.visit('/with_simple_html')
expect(@session.response_headers['Content-Type']).to match %r{text/html}
end
end
| ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/visit_spec.rb | lib/capybara/spec/session/visit_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#visit' do
it 'should fetch a response from the driver with a relative url' do
@session.visit('/')
expect(@session).to have_content('Hello world!')
@session.visit('/foo')
expect(@session).to have_content('Another World')
end
it 'should fet... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/body_spec.rb | lib/capybara/spec/session/body_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#body' do
it 'should return the unmodified page body' do
@session.visit('/')
expect(@session).to have_content('Hello world!') # wait for content to appear if visit is async
expect(@session.body).to include('Hello world!')
end
context 'encoding... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/save_page_spec.rb | lib/capybara/spec/session/save_page_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#save_page' do
let(:alternative_path) { File.join(Dir.pwd, 'save_and_open_page_tmp') }
before do
@old_save_path = Capybara.save_path
Capybara.save_path = nil
@session.visit('/foo')
end
after do
Capybara.save_path = @old_save_path
Dir... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/refresh_spec.rb | lib/capybara/spec/session/refresh_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/find_spec.rb | lib/capybara/spec/session/find_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#find' do
before do
@session.visit('/with_html')
end
after do
Capybara::Selector.remove(:monkey)
end
it 'should find the first element using the given locator' do
expect(@session.find('//h1').text).to eq('This is a test')
expect(@sess... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_title_spec.rb | lib/capybara/spec/session/assert_title_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_title' do
before do
@session.visit('/with_js')
end
it "should not raise if the page's title contains the given string" do
expect do
@session.assert_title('js')
end.not_to raise_error
end
it 'should not raise when given an em... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_ancestor_spec.rb | lib/capybara/spec/session/has_ancestor_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#have_ancestor' do
before do
@session.visit('/with_html')
end
it 'should assert an ancestor using the given locator' do
el = @session.find(:css, '#ancestor1')
expect(el).to have_ancestor(:css, '#ancestor2')
end
it 'should assert an ancest... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/save_and_open_page_spec.rb | lib/capybara/spec/session/save_and_open_page_spec.rb | # frozen_string_literal: true
require 'launchy'
Capybara::SpecHelper.spec '#save_and_open_page' do
before do
@session.visit '/foo'
end
after do
Dir.glob('capybara-*.html').each do |file|
FileUtils.rm(file)
end
end
it 'sends open method to launchy' do
allow(Launchy).to receive(:open)
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/click_link_or_button_spec.rb | lib/capybara/spec/session/click_link_or_button_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#click_link_or_button' do
it 'should click on a link' do
@session.visit('/with_html')
@session.click_link_or_button('labore')
expect(@session).to have_content('Bar')
end
it 'should click on a button' do
@session.visit('/form')
@session... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_style_spec.rb | lib/capybara/spec/session/assert_style_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_matches_style', requires: [:css] do
it 'should not raise if the elements style contains the given properties' do
@session.visit('/with_html')
expect do
@session.find(:css, '#first').assert_matches_style(display: 'block')
end.not_to ra... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/go_forward_spec.rb | lib/capybara/spec/session/go_forward_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#go_forward', requires: [:js] do
it 'should fetch a response from the driver from the previous page' do
@session.visit('/')
expect(@session).to have_content('Hello world!')
@session.visit('/foo')
expect(@session).to have_content('Another World'... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_select_spec.rb | lib/capybara/spec/session/has_select_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_select?' do
before { @session.visit('/form') }
it 'should be true if the field is on the page' do
expect(@session).to have_select('Locale')
expect(@session).to have_select('form_region')
expect(@session).to have_select('Languages')
expe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/dismiss_prompt_spec.rb | lib/capybara/spec/session/dismiss_prompt_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#dismiss_prompt', requires: [:modals] do
before do
@session.visit('/with_js')
end
it 'should dismiss the prompt' do
@session.dismiss_prompt do
@session.click_link('Open prompt')
end
expect(@session).to have_xpath("//a[@id='open-promp... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/selectors_spec.rb | lib/capybara/spec/session/selectors_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec Capybara::Selector do
before do
@session.visit('/form')
end
describe ':label selector' do
it 'finds a label by text' do
expect(@session.find(:label, 'Customer Name').text).to eq 'Customer Name'
end
it 'finds a label by for attribute ... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_none_selectors_spec.rb | lib/capybara/spec/session/has_none_selectors_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#have_none_of_selectors' do
before do
@session.visit('/with_html')
end
it 'should be false if any of the given locators are on the page' do
expect do
expect(@session).to have_none_of_selectors(:xpath, '//p', '//a')
end.to raise_error RSp... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_any_selectors_spec.rb | lib/capybara/spec/session/has_any_selectors_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#have_any_of_selectors' do
before do
@session.visit('/with_html')
end
it 'should be true if any of the given selectors are on the page' do
expect(@session).to have_any_of_selectors(:css, 'p a#foo', 'h2#blah', 'h2#h2two')
end
it 'should be fal... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/sibling_spec.rb | lib/capybara/spec/session/sibling_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#sibling' do
before do
@session.visit('/with_html')
end
after do
Capybara::Selector.remove(:monkey)
end
it 'should find a prior sibling element using the given locator' do
el = @session.find(:css, '#mid_sibling')
expect(el.sibling('//... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/accept_prompt_spec.rb | lib/capybara/spec/session/accept_prompt_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
before do
@session.visit('/with_js')
end
it 'should accept the prompt with no message' do
@session.accept_prompt do
@session.click_link('Open prompt')
end
expect(@session).to have_xpath("//a[@i... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/accept_alert_spec.rb | lib/capybara/spec/session/accept_alert_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
before do
@session.visit('/with_js')
end
it 'should accept the alert' do
@session.accept_alert do
@session.click_link('Open alert')
end
expect(@session).to have_xpath("//a[@id='open-alert' and @... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/click_link_spec.rb | lib/capybara/spec/session/click_link_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#click_link' do
before do
@session.visit('/with_html')
end
it 'should wait for asynchronous load', requires: [:js] do
Capybara.default_max_wait_time = 2
@session.visit('/with_js')
@session.click_link('Click me')
@session.click_link('Ha... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_all_selectors_spec.rb | lib/capybara/spec/session/has_all_selectors_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#have_all_of_selectors' do
before do
@session.visit('/with_html')
end
it 'should be true if the given selectors are on the page' do
expect(@session).to have_all_of_selectors(:css, 'p a#foo', 'h2#h2one', 'h2#h2two')
end
it 'should be false if ... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_element_spec.rb | lib/capybara/spec/session/has_element_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_element?' do
before do
@session.visit('/with_html')
end
it 'should be true if the given element is on the page' do
expect(@session).to have_element('a', id: 'foo')
expect(@session).to have_element('a', text: 'A link', href: '/with_simple_... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/save_screenshot_spec.rb | lib/capybara/spec/session/save_screenshot_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
let(:alternative_path) { File.join(Dir.pwd, 'save_screenshot_tmp') }
before do
@old_save_path = Capybara.save_path
Capybara.save_path = nil
@session.visit '/foo'
end
after do
Capybara.save_pa... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/node_spec.rb | lib/capybara/spec/session/node_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | true |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_current_path_spec.rb | lib/capybara/spec/session/has_current_path_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_current_path?' do
before do
@session.visit('/with_js')
end
it 'should be true if the page has the given current path' do
expect(@session).to have_current_path('/with_js')
end
it 'should allow regexp matches' do
expect(@session).to ha... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/assert_text_spec.rb | lib/capybara/spec/session/assert_text_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#assert_text' do
it 'should be true if the given text is on the page' do
@session.visit('/with_html')
expect(@session.assert_text('est')).to be(true)
expect(@session.assert_text('Lorem')).to be(true)
expect(@session.assert_text('Redirect')).to ... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/has_table_spec.rb | lib/capybara/spec/session/has_table_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#has_table?' do
before do
@session.visit('/tables')
end
it 'should be true if the table is on the page' do
expect(@session).to have_table('Villain')
expect(@session).to have_table('villain_table')
expect(@session).to have_table(:villain_ta... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/current_window_spec.rb | lib/capybara/spec/session/window/current_window_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
before do
@window = @session.current_window
@session.visit('/with_windows')
end
after do
(@session.windows - [@window]).each do |w|
@session.switch_to_window w
w.close
end
@session.... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/become_closed_spec.rb | lib/capybara/spec/session/window/become_closed_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
let!(:window) { @session.current_window }
let(:other_window) do
@session.window_opened_by do
@session.find(:css, '#openWindow').click
end
end
before do
@session.visit('/with_windows')
end
... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/window_opened_by_spec.rb | lib/capybara/spec/session/window/window_opened_by_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/windows_spec.rb | lib/capybara/spec/session/window/windows_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/within_window_spec.rb | lib/capybara/spec/session/window/within_window_spec.rb | # frozen_string_literal: true
Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
before do
@window = @session.current_window
@session.visit('/with_windows')
@session.find(:css, '#openTwoWindows').click
@session.document.synchronize(3, errors: [Capybara::CapybaraError]) do
rais... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
teamcapybara/capybara | https://github.com/teamcapybara/capybara/blob/b3325b198464b806f07ec2011ceb532d6d5cf4ab/lib/capybara/spec/session/window/switch_to_window_spec.rb | lib/capybara/spec/session/window/switch_to_window_spec.rb | # frozen_string_literal: true
# NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
# because of the methods being tested. In tests using Capybara this type of behavior should be implemented
# using Capybara provided assertions with builtin waiting behavior.
Capybara::SpecHe... | ruby | MIT | b3325b198464b806f07ec2011ceb532d6d5cf4ab | 2026-01-04T15:38:10.098638Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.