capybara 2.5.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
- data/.yard/templates_custom/default/class/html/setup.rb +17 -0
- data/.yard/yard_extensions.rb +78 -0
- data/.yardopts +1 -0
- data/History.md +413 -10
- data/License.txt +1 -1
- data/README.md +237 -130
- data/lib/capybara/config.rb +132 -0
- data/lib/capybara/cucumber.rb +3 -1
- data/lib/capybara/driver/base.rb +27 -6
- data/lib/capybara/driver/node.rb +14 -5
- data/lib/capybara/dsl.rb +2 -3
- data/lib/capybara/helpers.rb +13 -65
- data/lib/capybara/minitest/spec.rb +177 -0
- data/lib/capybara/minitest.rb +278 -0
- data/lib/capybara/node/actions.rb +180 -24
- data/lib/capybara/node/base.rb +17 -5
- data/lib/capybara/node/document.rb +5 -0
- data/lib/capybara/node/document_matchers.rb +15 -14
- data/lib/capybara/node/element.rb +55 -7
- data/lib/capybara/node/finders.rb +179 -67
- data/lib/capybara/node/matchers.rb +301 -105
- data/lib/capybara/node/simple.rb +15 -4
- data/lib/capybara/queries/ancestor_query.rb +25 -0
- data/lib/capybara/queries/base_query.rb +69 -3
- data/lib/capybara/queries/current_path_query.rb +17 -8
- data/lib/capybara/queries/match_query.rb +19 -0
- data/lib/capybara/queries/selector_query.rb +251 -0
- data/lib/capybara/queries/sibling_query.rb +25 -0
- data/lib/capybara/queries/text_query.rb +67 -16
- data/lib/capybara/queries/title_query.rb +4 -2
- data/lib/capybara/query.rb +3 -131
- data/lib/capybara/rack_test/browser.rb +14 -5
- data/lib/capybara/rack_test/css_handlers.rb +1 -0
- data/lib/capybara/rack_test/driver.rb +15 -8
- data/lib/capybara/rack_test/form.rb +34 -12
- data/lib/capybara/rack_test/node.rb +29 -12
- data/lib/capybara/rails.rb +3 -3
- data/lib/capybara/result.rb +104 -9
- data/lib/capybara/rspec/compound.rb +95 -0
- data/lib/capybara/rspec/features.rb +17 -6
- data/lib/capybara/rspec/matcher_proxies.rb +45 -0
- data/lib/capybara/rspec/matchers.rb +199 -80
- data/lib/capybara/rspec.rb +4 -2
- data/lib/capybara/selector/css.rb +30 -0
- data/lib/capybara/selector/filter.rb +20 -0
- data/lib/capybara/selector/filter_set.rb +74 -0
- data/lib/capybara/selector/filters/base.rb +33 -0
- data/lib/capybara/selector/filters/expression_filter.rb +40 -0
- data/lib/capybara/selector/filters/node_filter.rb +27 -0
- data/lib/capybara/selector/selector.rb +276 -0
- data/lib/capybara/selector.rb +452 -157
- data/lib/capybara/selenium/driver.rb +282 -81
- data/lib/capybara/selenium/node.rb +144 -46
- data/lib/capybara/server.rb +59 -16
- data/lib/capybara/session/config.rb +114 -0
- data/lib/capybara/session/matchers.rb +29 -19
- data/lib/capybara/session.rb +378 -143
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +13 -791
- data/lib/capybara/spec/public/jquery.js +4 -9045
- data/lib/capybara/spec/public/test.js +45 -11
- data/lib/capybara/spec/session/accept_alert_spec.rb +30 -7
- data/lib/capybara/spec/session/accept_confirm_spec.rb +14 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +35 -6
- data/lib/capybara/spec/session/all_spec.rb +45 -32
- data/lib/capybara/spec/session/ancestor_spec.rb +85 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +110 -0
- data/lib/capybara/spec/session/assert_current_path.rb +15 -2
- data/lib/capybara/spec/session/assert_selector.rb +29 -28
- data/lib/capybara/spec/session/assert_text.rb +59 -20
- data/lib/capybara/spec/session/assert_title.rb +25 -11
- data/lib/capybara/spec/session/attach_file_spec.rb +42 -4
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +90 -14
- data/lib/capybara/spec/session/choose_spec.rb +31 -5
- data/lib/capybara/spec/session/click_button_spec.rb +20 -9
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +15 -9
- data/lib/capybara/spec/session/click_link_spec.rb +39 -15
- data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
- data/lib/capybara/spec/session/current_url_spec.rb +12 -3
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +6 -5
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +4 -3
- data/lib/capybara/spec/session/element/assert_match_selector.rb +36 -0
- data/lib/capybara/spec/session/element/match_css_spec.rb +23 -0
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +106 -0
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +22 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +23 -1
- data/lib/capybara/spec/session/execute_script_spec.rb +22 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +50 -32
- data/lib/capybara/spec/session/find_button_spec.rb +43 -2
- data/lib/capybara/spec/session/find_by_id_spec.rb +3 -2
- data/lib/capybara/spec/session/find_field_spec.rb +42 -6
- data/lib/capybara/spec/session/find_link_spec.rb +22 -3
- data/lib/capybara/spec/session/find_spec.rb +103 -57
- data/lib/capybara/spec/session/first_spec.rb +34 -18
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +103 -0
- data/lib/capybara/spec/session/{within_frame_spec.rb → frame/within_frame_spec.rb} +44 -2
- data/lib/capybara/spec/session/go_back_spec.rb +2 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_button_spec.rb +17 -8
- data/lib/capybara/spec/session/has_css_spec.rb +85 -73
- data/lib/capybara/spec/session/has_current_path_spec.rb +91 -7
- data/lib/capybara/spec/session/has_field_spec.rb +93 -58
- data/lib/capybara/spec/session/has_link_spec.rb +9 -8
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
- data/lib/capybara/spec/session/has_select_spec.rb +159 -59
- data/lib/capybara/spec/session/has_selector_spec.rb +64 -28
- data/lib/capybara/spec/session/has_table_spec.rb +1 -0
- data/lib/capybara/spec/session/has_text_spec.rb +27 -12
- data/lib/capybara/spec/session/has_title_spec.rb +22 -4
- data/lib/capybara/spec/session/has_xpath_spec.rb +32 -29
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +4 -3
- data/lib/capybara/spec/session/node_spec.rb +198 -38
- data/lib/capybara/spec/session/refresh_spec.rb +28 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +46 -5
- data/lib/capybara/spec/session/response_code.rb +2 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -5
- data/lib/capybara/spec/session/save_page_spec.rb +34 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
- data/lib/capybara/spec/session/screenshot_spec.rb +4 -2
- data/lib/capybara/spec/session/select_spec.rb +34 -32
- data/lib/capybara/spec/session/selectors_spec.rb +65 -0
- data/lib/capybara/spec/session/sibling_spec.rb +52 -0
- data/lib/capybara/spec/session/text_spec.rb +4 -4
- data/lib/capybara/spec/session/title_spec.rb +2 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +42 -2
- data/lib/capybara/spec/session/unselect_spec.rb +17 -16
- data/lib/capybara/spec/session/visit_spec.rb +77 -2
- data/lib/capybara/spec/session/window/become_closed_spec.rb +12 -11
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -11
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +7 -4
- data/lib/capybara/spec/session/window/window_spec.rb +36 -29
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
- data/lib/capybara/spec/session/window/within_window_spec.rb +31 -7
- data/lib/capybara/spec/session/within_spec.rb +14 -6
- data/lib/capybara/spec/spec_helper.rb +37 -4
- data/lib/capybara/spec/test_app.rb +15 -3
- data/lib/capybara/spec/views/buttons.erb +1 -0
- data/lib/capybara/spec/views/fieldsets.erb +2 -1
- data/lib/capybara/spec/views/form.erb +169 -9
- data/lib/capybara/spec/views/frame_child.erb +10 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +3 -2
- data/lib/capybara/spec/views/frame_two.erb +2 -1
- data/lib/capybara/spec/views/header_links.erb +1 -0
- data/lib/capybara/spec/views/host_links.erb +1 -0
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/path.erb +1 -0
- data/lib/capybara/spec/views/popup_one.erb +1 -0
- data/lib/capybara/spec/views/popup_two.erb +1 -0
- data/lib/capybara/spec/views/postback.erb +2 -1
- data/lib/capybara/spec/views/tables.erb +1 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -0
- data/lib/capybara/spec/views/with_count.erb +2 -1
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +7 -1
- data/lib/capybara/spec/views/with_html.erb +40 -2
- data/lib/capybara/spec/views/with_html_entities.erb +1 -0
- data/lib/capybara/spec/views/with_js.erb +32 -1
- data/lib/capybara/spec/views/with_scope.erb +1 -0
- data/lib/capybara/spec/views/with_simple_html.erb +2 -1
- data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
- data/lib/capybara/spec/views/with_title.erb +2 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +14 -0
- data/lib/capybara/spec/views/with_windows.erb +7 -0
- data/lib/capybara/spec/views/within_frames.erb +3 -2
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +20 -3
- data/lib/capybara.rb +189 -93
- data/spec/basic_node_spec.rb +7 -6
- data/spec/capybara_spec.rb +90 -4
- data/spec/dsl_spec.rb +3 -1
- data/spec/filter_set_spec.rb +28 -0
- data/spec/fixtures/capybara.csv +1 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +5 -1
- data/spec/minitest_spec.rb +130 -0
- data/spec/minitest_spec_spec.rb +135 -0
- data/spec/per_session_config_spec.rb +67 -0
- data/spec/rack_test_spec.rb +50 -7
- data/spec/result_spec.rb +76 -0
- data/spec/rspec/features_spec.rb +21 -8
- data/spec/rspec/scenarios_spec.rb +21 -0
- data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +160 -54
- data/spec/rspec/views_spec.rb +5 -0
- data/spec/rspec_matchers_spec.rb +46 -0
- data/spec/rspec_spec.rb +79 -1
- data/spec/selector_spec.rb +199 -0
- data/spec/selenium_spec_chrome.rb +54 -9
- data/spec/selenium_spec_firefox.rb +68 -0
- data/spec/selenium_spec_marionette.rb +127 -0
- data/spec/server_spec.rb +102 -14
- data/spec/session_spec.rb +54 -0
- data/spec/shared_selenium_session.rb +215 -0
- data/spec/spec_helper.rb +7 -0
- metadata +140 -15
- data/spec/selenium_spec.rb +0 -128
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
3
|
+
require 'selenium-webdriver'
|
|
2
4
|
|
|
3
5
|
RSpec.describe Capybara::Selenium::Driver do
|
|
4
6
|
it "should exit with a non-zero exit status" do
|
|
5
|
-
|
|
7
|
+
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
|
8
|
+
options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false) if ENV['LEGACY_FIREFOX']
|
|
9
|
+
browser = Capybara::Selenium::Driver.new(TestApp, options).browser
|
|
6
10
|
expect(true).to eq(false)
|
|
7
11
|
end
|
|
8
12
|
end
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
3
|
+
require 'selenium-webdriver'
|
|
2
4
|
|
|
3
5
|
RSpec.describe Capybara::Selenium::Driver do
|
|
4
6
|
it "should exit with a zero exit status" do
|
|
5
|
-
|
|
7
|
+
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
|
8
|
+
options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false) if ENV['LEGACY_FIREFOX']
|
|
9
|
+
browser = Capybara::Selenium::Driver.new(TestApp, options ).browser
|
|
6
10
|
expect(true).to eq(true)
|
|
7
11
|
end
|
|
8
12
|
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'capybara/minitest'
|
|
4
|
+
|
|
5
|
+
class MinitestTest < Minitest::Test
|
|
6
|
+
include Capybara::DSL
|
|
7
|
+
include Capybara::Minitest::Assertions
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
visit('/form')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
Capybara.reset_sessions!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_assert_text
|
|
18
|
+
assert_text('Form')
|
|
19
|
+
assert_no_text('Not on the page')
|
|
20
|
+
refute_text('Also Not on the page')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_assert_title
|
|
24
|
+
visit('/with_title')
|
|
25
|
+
assert_title('Test Title')
|
|
26
|
+
assert_no_title('Not the title')
|
|
27
|
+
refute_title('Not the title')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_assert_current_path
|
|
31
|
+
assert_current_path('/form')
|
|
32
|
+
assert_no_current_path('/not_form')
|
|
33
|
+
refute_current_path('/not_form')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_assert_xpath
|
|
37
|
+
assert_xpath('.//select[@id="form_title"]')
|
|
38
|
+
assert_xpath('.//select', count: 1) { |el| el[:id] == "form_title" }
|
|
39
|
+
assert_no_xpath('.//select[@id="not_form_title"]')
|
|
40
|
+
assert_no_xpath('.//select') { |el| el[:id] == "not_form_title"}
|
|
41
|
+
refute_xpath('.//select[@id="not_form_title"]')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_assert_css
|
|
45
|
+
assert_css('select#form_title')
|
|
46
|
+
assert_no_css('select#not_form_title')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_assert_link
|
|
50
|
+
visit('/with_html')
|
|
51
|
+
assert_link('A link')
|
|
52
|
+
assert_link(count: 1){ |el| el.text == 'A link'}
|
|
53
|
+
assert_no_link('Not on page')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_assert_button
|
|
57
|
+
assert_button('fresh_btn')
|
|
58
|
+
assert_button(count: 1){ |el| el[:id] == 'fresh_btn' }
|
|
59
|
+
assert_no_button('not_btn')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_assert_field
|
|
63
|
+
assert_field('customer_email')
|
|
64
|
+
assert_no_field('not_on_the_form')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_assert_select
|
|
68
|
+
assert_select('form_title')
|
|
69
|
+
assert_no_select('not_form_title')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_assert_checked_field
|
|
73
|
+
assert_checked_field('form_pets_dog')
|
|
74
|
+
assert_no_checked_field('form_pets_cat')
|
|
75
|
+
refute_checked_field('form_pets_snake')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_assert_unchecked_field
|
|
79
|
+
assert_unchecked_field('form_pets_cat')
|
|
80
|
+
assert_no_unchecked_field('form_pets_dog')
|
|
81
|
+
refute_unchecked_field('form_pets_snake')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_assert_table
|
|
85
|
+
visit('/tables')
|
|
86
|
+
assert_table('agent_table')
|
|
87
|
+
assert_no_table('not_on_form')
|
|
88
|
+
refute_table('not_on_form')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_assert_all_of_selectors
|
|
92
|
+
assert_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_assert_none_of_selectors
|
|
96
|
+
assert_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_assert_matches_selector
|
|
100
|
+
assert_matches_selector(find(:field, 'customer_email'), :field, 'customer_email')
|
|
101
|
+
assert_not_matches_selector(find(:select, 'form_title'), :field, 'customer_email')
|
|
102
|
+
refute_matches_selector(find(:select, 'form_title'), :field, 'customer_email')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_assert_matches_css
|
|
106
|
+
assert_matches_css(find(:select, 'form_title'), 'select#form_title')
|
|
107
|
+
refute_matches_css(find(:select, 'form_title'), 'select#form_other_title')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_assert_matches_xpath
|
|
111
|
+
assert_matches_xpath(find(:select, 'form_title'), './/select[@id="form_title"]')
|
|
112
|
+
refute_matches_xpath(find(:select, 'form_title'), './/select[@id="form_other_title"]')
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
RSpec.describe 'capybara/minitest' do
|
|
117
|
+
before do
|
|
118
|
+
Capybara.current_driver = :rack_test
|
|
119
|
+
Capybara.app = TestApp
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should support minitest" do
|
|
123
|
+
output = StringIO.new
|
|
124
|
+
reporter = Minitest::SummaryReporter.new(output)
|
|
125
|
+
reporter.start
|
|
126
|
+
MinitestTest.run reporter, {}
|
|
127
|
+
reporter.report
|
|
128
|
+
expect(output.string).to include("17 runs, 44 assertions, 0 failures, 0 errors, 0 skips")
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'capybara/minitest'
|
|
4
|
+
require 'capybara/minitest/spec'
|
|
5
|
+
|
|
6
|
+
class MinitestSpecTest < Minitest::Spec
|
|
7
|
+
include ::Capybara::DSL
|
|
8
|
+
include ::Capybara::Minitest::Assertions
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
visit('/form')
|
|
12
|
+
end
|
|
13
|
+
after do
|
|
14
|
+
Capybara.reset_sessions!
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "supports text expectations" do
|
|
18
|
+
page.must_have_text('Form', minimum: 1)
|
|
19
|
+
page.wont_have_text('Not a form')
|
|
20
|
+
form = find(:css, 'form', text: 'Title')
|
|
21
|
+
form.must_have_text('Customer Email')
|
|
22
|
+
form.wont_have_text('Some other email')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "supports current_path expectations" do
|
|
26
|
+
page.must_have_current_path('/form')
|
|
27
|
+
page.wont_have_current_path('/form2')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "supports title expectations" do
|
|
31
|
+
visit('/with_title')
|
|
32
|
+
page.must_have_title('Test Title')
|
|
33
|
+
page.wont_have_title('Not the title')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "supports xpath expectations" do
|
|
37
|
+
page.must_have_xpath('.//input[@id="customer_email"]')
|
|
38
|
+
page.wont_have_xpath('.//select[@id="not_form_title"]')
|
|
39
|
+
page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == "not_customer_email" }
|
|
40
|
+
select = find(:select, 'form_title')
|
|
41
|
+
select.must_have_xpath('.//option[@class="title"]')
|
|
42
|
+
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled?}
|
|
43
|
+
select.wont_have_xpath('.//input[@id="customer_email"]')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "support css expectations" do
|
|
47
|
+
page.must_have_css('input#customer_email')
|
|
48
|
+
page.wont_have_css('select#not_form_title')
|
|
49
|
+
el = find(:select, 'form_title')
|
|
50
|
+
el.must_have_css('option.title')
|
|
51
|
+
el.wont_have_css('input#customer_email')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "supports link expectations" do
|
|
55
|
+
visit('/with_html')
|
|
56
|
+
page.must_have_link('A link')
|
|
57
|
+
page.wont_have_link('Not on page')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "supports button expectations" do
|
|
61
|
+
page.must_have_button('fresh_btn')
|
|
62
|
+
page.wont_have_button('not_btn')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "supports field expectations" do
|
|
66
|
+
page.must_have_field('customer_email')
|
|
67
|
+
page.wont_have_field('not_on_the_form')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "supports select expectations" do
|
|
71
|
+
page.must_have_select('form_title')
|
|
72
|
+
page.wont_have_select('not_form_title')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "supports checked_field expectations" do
|
|
76
|
+
page.must_have_checked_field('form_pets_dog')
|
|
77
|
+
page.wont_have_checked_field('form_pets_cat')
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "supports unchecked_field expectations" do
|
|
81
|
+
page.must_have_unchecked_field('form_pets_cat')
|
|
82
|
+
page.wont_have_unchecked_field('form_pets_dog')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "supports table expectations" do
|
|
86
|
+
visit('/tables')
|
|
87
|
+
page.must_have_table('agent_table')
|
|
88
|
+
page.wont_have_table('not_on_form')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "supports all_of_selectors expectations" do
|
|
92
|
+
page.must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "supports none_of_selectors expectations" do
|
|
96
|
+
page.must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "supports match_selector expectations" do
|
|
100
|
+
find(:field, 'customer_email').must_match_selector(:field, 'customer_email')
|
|
101
|
+
find(:select, 'form_title').wont_match_selector(:field, 'customer_email')
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "supports match_css expectations" do
|
|
105
|
+
find(:select, 'form_title').must_match_css('select#form_title')
|
|
106
|
+
find(:select, 'form_title').wont_match_css('select#form_other_title')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "supports match_xpath expectations" do
|
|
110
|
+
find(:select, 'form_title').must_match_xpath('.//select[@id="form_title"]')
|
|
111
|
+
find(:select, 'form_title').wont_match_xpath('.//select[@id="not_on_page"]')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "handles failures" do
|
|
115
|
+
page.must_have_select('non_existing_form_title')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
RSpec.describe 'capybara/minitest/spec' do
|
|
120
|
+
before do
|
|
121
|
+
Capybara.current_driver = :rack_test
|
|
122
|
+
Capybara.app = TestApp
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should support minitest spec" do
|
|
126
|
+
output = StringIO.new
|
|
127
|
+
reporter = Minitest::SummaryReporter.new(output)
|
|
128
|
+
reporter.start
|
|
129
|
+
MinitestSpecTest.run reporter, {}
|
|
130
|
+
reporter.report
|
|
131
|
+
expect(output.string).to include("18 runs, 41 assertions, 1 failures, 0 errors, 0 skips")
|
|
132
|
+
#Make sure error messages are displayed
|
|
133
|
+
expect(output.string).to include('expected to find visible select box "non_existing_form_title" that is not disabled but there were no matches')
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'capybara/dsl'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Capybara::SessionConfig do
|
|
6
|
+
describe "threadsafe" do
|
|
7
|
+
it "defaults to global session options" do
|
|
8
|
+
Capybara.threadsafe = true
|
|
9
|
+
session = Capybara::Session.new(:rack_test, TestApp)
|
|
10
|
+
[:default_host, :app_host, :save_and_open_page_path,
|
|
11
|
+
:always_include_port, :run_server, :default_selector, :default_max_wait_time, :ignore_hidden_elements,
|
|
12
|
+
:automatic_reload, :match, :exact, :raise_server_errors, :visible_text_only, :wait_on_first_by_default,
|
|
13
|
+
:automatic_label_click, :enable_aria_label,
|
|
14
|
+
:save_path, :exact_options, :asset_host].each do |m|
|
|
15
|
+
expect(session.config.public_send(m)).to eq Capybara.public_send(m)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "doesn't change global session when changed" do
|
|
20
|
+
Capybara.threadsafe = true
|
|
21
|
+
host = "http://my.example.com"
|
|
22
|
+
session = Capybara::Session.new(:rack_test, TestApp) do |config|
|
|
23
|
+
config.default_host = host
|
|
24
|
+
config.automatic_label_click = !config.automatic_label_click
|
|
25
|
+
config.server_errors << ArgumentError
|
|
26
|
+
end
|
|
27
|
+
expect(Capybara.default_host).not_to eq host
|
|
28
|
+
expect(session.config.default_host).to eq host
|
|
29
|
+
expect(Capybara.automatic_label_click).not_to eq session.config.automatic_label_click
|
|
30
|
+
expect(Capybara.server_errors).not_to eq session.config.server_errors
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "doesn't allow session configuration block when false" do
|
|
34
|
+
Capybara.threadsafe = false
|
|
35
|
+
expect do
|
|
36
|
+
Capybara::Session.new(:rack_test, TestApp) { |config| }
|
|
37
|
+
end.to raise_error "A configuration block is only accepted when Capybara.threadsafe == true"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "doesn't allow session config when false" do
|
|
41
|
+
Capybara.threadsafe = false
|
|
42
|
+
session = Capybara::Session.new(:rack_test, TestApp)
|
|
43
|
+
expect { session.config.default_selector = :title }.to raise_error(/Per session settings are only supported when Capybara.threadsafe == true/)
|
|
44
|
+
expect do
|
|
45
|
+
session.configure do |config|
|
|
46
|
+
config.exact = true
|
|
47
|
+
end
|
|
48
|
+
end.to raise_error(/Session configuration is only supported when Capybara.threadsafe == true/)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "uses the config from the session" do
|
|
52
|
+
Capybara.threadsafe = true
|
|
53
|
+
session = Capybara::Session.new(:rack_test, TestApp) do |config|
|
|
54
|
+
config.default_selector = :link
|
|
55
|
+
end
|
|
56
|
+
session.visit('/with_html')
|
|
57
|
+
expect(session.find('foo').tag_name).to eq 'a'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "won't change threadsafe once a session is created" do
|
|
61
|
+
Capybara.threadsafe = true
|
|
62
|
+
Capybara.threadsafe = false
|
|
63
|
+
Capybara::Session.new(:rack_test, TestApp)
|
|
64
|
+
expect { Capybara.threadsafe = true }.to raise_error(/Threadsafe setting cannot be changed once a session is created/)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
data/spec/rack_test_spec.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
module TestSessions
|
|
4
5
|
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :
|
|
8
|
+
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: [
|
|
8
9
|
:js,
|
|
9
10
|
:modals,
|
|
10
11
|
:screenshot,
|
|
@@ -78,6 +79,48 @@ RSpec.describe Capybara::Session do
|
|
|
78
79
|
expect(@session.html).to include('Successfully ignored empty file field.')
|
|
79
80
|
end
|
|
80
81
|
end
|
|
82
|
+
|
|
83
|
+
it "should not submit an obsolete mime type" do
|
|
84
|
+
@test_jpg_file_path = File.expand_path('fixtures/capybara.csv', File.dirname(__FILE__))
|
|
85
|
+
@session.visit("/form")
|
|
86
|
+
@session.attach_file "form_document", @test_jpg_file_path
|
|
87
|
+
@session.click_button('Upload Single')
|
|
88
|
+
expect(@session).to have_content("Content-type: text/csv")
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe "#click" do
|
|
93
|
+
context "on a label" do
|
|
94
|
+
it "should toggle the associated checkbox" do
|
|
95
|
+
@session.visit("/form")
|
|
96
|
+
expect(@session).to have_unchecked_field('form_pets_cat')
|
|
97
|
+
@session.find(:label, 'Cat').click
|
|
98
|
+
expect(@session).to have_checked_field('form_pets_cat')
|
|
99
|
+
@session.find(:label, 'Cat').click
|
|
100
|
+
expect(@session).to have_unchecked_field('form_pets_cat')
|
|
101
|
+
@session.find(:label, 'McLaren').click
|
|
102
|
+
expect(@session).to have_checked_field('form_cars_mclaren', visible: :hidden)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should toggle the associated radio" do
|
|
106
|
+
@session.visit("/form")
|
|
107
|
+
expect(@session).to have_unchecked_field('gender_male')
|
|
108
|
+
@session.find(:label, 'Male').click
|
|
109
|
+
expect(@session).to have_checked_field('gender_male')
|
|
110
|
+
@session.find(:label, 'Female').click
|
|
111
|
+
expect(@session).to have_unchecked_field('gender_male')
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#text' do
|
|
117
|
+
it "should return original text content for textareas" do
|
|
118
|
+
@session.visit('/with_html')
|
|
119
|
+
@session.find_field('normal', type: 'textarea', with: 'banana').set('hello')
|
|
120
|
+
normal = @session.find(:css, '#normal')
|
|
121
|
+
expect(normal.value).to eq 'hello'
|
|
122
|
+
expect(normal.text).to eq 'banana'
|
|
123
|
+
end
|
|
81
124
|
end
|
|
82
125
|
end
|
|
83
126
|
end
|
|
@@ -89,27 +132,27 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
|
89
132
|
|
|
90
133
|
describe ':headers option' do
|
|
91
134
|
it 'should always set headers' do
|
|
92
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
135
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
|
93
136
|
@driver.visit('/get_header')
|
|
94
137
|
expect(@driver.html).to include('foobar')
|
|
95
138
|
end
|
|
96
139
|
|
|
97
140
|
it 'should keep headers on link clicks' do
|
|
98
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
141
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
|
99
142
|
@driver.visit('/header_links')
|
|
100
143
|
@driver.find_xpath('.//a').first.click
|
|
101
144
|
expect(@driver.html).to include('foobar')
|
|
102
145
|
end
|
|
103
146
|
|
|
104
147
|
it 'should keep headers on form submit' do
|
|
105
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
148
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
|
106
149
|
@driver.visit('/header_links')
|
|
107
150
|
@driver.find_xpath('.//input').first.click
|
|
108
151
|
expect(@driver.html).to include('foobar')
|
|
109
152
|
end
|
|
110
153
|
|
|
111
154
|
it 'should keep headers on redirects' do
|
|
112
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
155
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
|
113
156
|
@driver.visit('/get_header_via_redirect')
|
|
114
157
|
expect(@driver.html).to include('foobar')
|
|
115
158
|
end
|
|
@@ -125,7 +168,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
|
125
168
|
end
|
|
126
169
|
|
|
127
170
|
it "is possible to not follow redirects" do
|
|
128
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
171
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
|
|
129
172
|
|
|
130
173
|
@driver.visit('/redirect')
|
|
131
174
|
expect(@driver.response.header['Location']).to match %r{/redirect_again$}
|
|
@@ -153,7 +196,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
|
153
196
|
|
|
154
197
|
context "with 21 redirect limit" do
|
|
155
198
|
before do
|
|
156
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
|
199
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21)
|
|
157
200
|
end
|
|
158
201
|
|
|
159
202
|
it "should follow 21 redirects" do
|
data/spec/result_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Capybara::Result do
|
|
@@ -62,4 +63,79 @@ RSpec.describe Capybara::Result do
|
|
|
62
63
|
el.text == 'Gamma'
|
|
63
64
|
end).to eq(2)
|
|
64
65
|
end
|
|
66
|
+
|
|
67
|
+
it 'supports all modes of []' do
|
|
68
|
+
expect(result[1].text).to eq 'Beta'
|
|
69
|
+
expect(result[0,2].map(&:text)).to eq ['Alpha', 'Beta']
|
|
70
|
+
expect(result[1..3].map(&:text)).to eq ['Beta', 'Gamma', 'Delta']
|
|
71
|
+
expect(result[-1].text).to eq 'Delta'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'works with filter blocks' do
|
|
75
|
+
result = string.all('//li') { |node| node.text == 'Alpha' }
|
|
76
|
+
expect(result.size).to eq 1
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should catch invalid element errors during filtering' do
|
|
80
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
|
|
81
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError] )))
|
|
82
|
+
result = string.all('//li', text: 'Alpha')
|
|
83
|
+
expect(result.size).to eq 0
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'should return non-invalid element errors during filtering' do
|
|
87
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
|
|
88
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError] )))
|
|
89
|
+
expect do
|
|
90
|
+
string.all('//li', text: 'Alpha').to_a
|
|
91
|
+
end.to raise_error(StandardError)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#Not a great test but it indirectly tests what is needed
|
|
95
|
+
it "should evaluate filters lazily" do
|
|
96
|
+
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
|
97
|
+
#Not processed until accessed
|
|
98
|
+
expect(result.instance_variable_get('@result_cache').size).to be 0
|
|
99
|
+
|
|
100
|
+
#Only one retrieved when needed
|
|
101
|
+
result.first
|
|
102
|
+
expect(result.instance_variable_get('@result_cache').size).to be 1
|
|
103
|
+
|
|
104
|
+
#works for indexed access
|
|
105
|
+
result[0]
|
|
106
|
+
expect(result.instance_variable_get('@result_cache').size).to be 1
|
|
107
|
+
|
|
108
|
+
result[2]
|
|
109
|
+
expect(result.instance_variable_get('@result_cache').size).to be 3
|
|
110
|
+
|
|
111
|
+
#All cached when converted to array
|
|
112
|
+
result.to_a
|
|
113
|
+
expect(result.instance_variable_get('@result_cache').size).to eq 4
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context '#each' do
|
|
117
|
+
it 'lazily evaluates' do
|
|
118
|
+
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
|
119
|
+
results=[]
|
|
120
|
+
result.each do |el|
|
|
121
|
+
results << el
|
|
122
|
+
expect(result.instance_variable_get('@result_cache').size).to eq results.size
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
expect(results.size).to eq 4
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context 'without a block' do
|
|
129
|
+
it 'returns an iterator' do
|
|
130
|
+
expect(result.each).to be_a(Enumerator)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'lazily evaluates' do
|
|
134
|
+
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
|
135
|
+
result.each.with_index do |el, idx|
|
|
136
|
+
expect(result.instance_variable_get('@result_cache').size).to eq(idx+1) # 0 indexing
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
65
141
|
end
|
data/spec/rspec/features_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
require 'capybara/rspec'
|
|
3
4
|
|
|
@@ -5,11 +6,11 @@ RSpec.configuration.before(:each, { file_path: "./spec/rspec/features_spec.rb" }
|
|
|
5
6
|
@in_filtered_hook = true
|
|
6
7
|
end
|
|
7
8
|
|
|
8
|
-
feature "Capybara's feature DSL" do
|
|
9
|
+
feature "Capybara's feature DSL" do
|
|
9
10
|
background do
|
|
10
11
|
@in_background = true
|
|
11
12
|
end
|
|
12
|
-
|
|
13
|
+
|
|
13
14
|
def current_example(context)
|
|
14
15
|
RSpec.respond_to?(:current_example) ? RSpec.current_example : context.example
|
|
15
16
|
end
|
|
@@ -19,7 +20,7 @@ feature "Capybara's feature DSL" do
|
|
|
19
20
|
expect(page).to have_content('Hello world!')
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
scenario "preserves description" do
|
|
23
|
+
scenario "preserves description" do
|
|
23
24
|
expect(current_example(self).metadata[:full_description])
|
|
24
25
|
.to eq("Capybara's feature DSL preserves description")
|
|
25
26
|
end
|
|
@@ -70,13 +71,25 @@ feature "given and given! aliases to let and let!" do
|
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
73
|
|
|
73
|
-
feature "if xscenario aliases to pending then" do
|
|
74
|
-
xscenario "this test should be 'temporarily disabled with xscenario'" do
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
74
|
feature "Capybara's feature DSL with driver", :driver => :culerity do
|
|
79
75
|
scenario "switches driver" do
|
|
80
76
|
expect(Capybara.current_driver).to eq(:culerity)
|
|
81
77
|
end
|
|
82
78
|
end
|
|
79
|
+
|
|
80
|
+
if RSpec::Core::Version::STRING.to_f >= 3.0
|
|
81
|
+
xfeature "if xfeature aliases to pending then" do
|
|
82
|
+
scenario "this should be 'temporarily disabled with xfeature'" do; end
|
|
83
|
+
scenario "this also should be 'temporarily disabled with xfeature'" do; end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
ffeature "if ffeature aliases focused tag then" do
|
|
87
|
+
scenario "scenario inside this feature has metatag focus tag" do |example|
|
|
88
|
+
expect(example.metadata[:focus]).to eq true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
scenario "other scenarios also has metatag focus tag " do |example|
|
|
92
|
+
expect(example.metadata[:focus]).to eq true
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'capybara/rspec'
|
|
4
|
+
|
|
5
|
+
RSpec.configuration.before(:each, { file_path: "./spec/rspec/scenarios_spec.rb" } ) do
|
|
6
|
+
@in_filtered_hook = true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if RSpec::Core::Version::STRING.to_f >= 3.0
|
|
10
|
+
feature "if fscenario aliases focused tag then" do
|
|
11
|
+
fscenario "scenario should have focused meta tag" do |example|
|
|
12
|
+
expect(example.metadata[:focus]).to eq true
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
feature "if xscenario aliases to pending then" do
|
|
18
|
+
xscenario "this test should be 'temporarily disabled with xscenario'" do
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|