capybara 2.5.0 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
2
3
|
before(:each) do
|
3
4
|
@session.visit('/within_frames')
|
4
5
|
end
|
@@ -8,40 +9,59 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|
8
9
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
9
10
|
end
|
10
11
|
end
|
12
|
+
|
11
13
|
it "should find the div in FrameTwo" do
|
12
14
|
@session.within_frame("frameTwo") do
|
13
15
|
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
14
16
|
end
|
15
17
|
end
|
18
|
+
|
16
19
|
it "should find the text div in the main window after finding text in frameOne" do
|
17
20
|
@session.within_frame("frameOne") do
|
18
21
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
19
22
|
end
|
20
23
|
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
21
24
|
end
|
25
|
+
|
22
26
|
it "should find the text div in the main window after finding text in frameTwo" do
|
23
27
|
@session.within_frame("frameTwo") do
|
24
28
|
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
25
29
|
end
|
26
30
|
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
27
31
|
end
|
32
|
+
|
28
33
|
it "should return the result of executing the block" do
|
29
34
|
expect(@session.within_frame("frameOne") { "return value" }).to eql "return value"
|
30
35
|
end
|
36
|
+
|
31
37
|
it "should find the div given Element" do
|
32
38
|
element = @session.find(:id, 'frameOne')
|
33
39
|
@session.within_frame element do
|
34
40
|
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
35
41
|
end
|
36
42
|
end
|
43
|
+
|
44
|
+
it "should find the div given selector and locator" do
|
45
|
+
@session.within_frame(:css, '#frameOne') do
|
46
|
+
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should default to the :frame selector kind when only options passed" do
|
51
|
+
@session.within_frame(name: 'my frame one') do
|
52
|
+
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
37
56
|
it "should find multiple nested frames" do
|
38
57
|
@session.within_frame 'parentFrame' do
|
39
58
|
@session.within_frame 'childFrame' do
|
40
59
|
@session.within_frame 'grandchildFrame1' do end
|
41
60
|
@session.within_frame 'grandchildFrame2' do end
|
42
|
-
end
|
61
|
+
end
|
43
62
|
end
|
44
63
|
end
|
64
|
+
|
45
65
|
it "should reset scope when changing frames" do
|
46
66
|
@session.within(:css, '#divInMainWindow') do
|
47
67
|
@session.within_frame 'parentFrame' do
|
@@ -49,4 +69,26 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|
49
69
|
end
|
50
70
|
end
|
51
71
|
end
|
72
|
+
|
73
|
+
it "works if the frame is closed", requires: [:frames, :js] do
|
74
|
+
@session.within_frame 'parentFrame' do
|
75
|
+
@session.within_frame 'childFrame' do
|
76
|
+
@session.click_link 'Close Window'
|
77
|
+
end
|
78
|
+
expect(@session).to have_selector(:css, 'body#parentBody')
|
79
|
+
expect(@session).not_to have_selector(:css, '#childFrame')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should support the driver #switch_to_frame api" do
|
84
|
+
# This test is purely to notify driver authors to update their API.
|
85
|
+
# The #switch_to_frame API will be required in the next version (> 2.8) of Capybara for frames support.
|
86
|
+
# It should not be used as an example of code for users.
|
87
|
+
frame = @session.find(:frame, "frameOne")
|
88
|
+
expect {
|
89
|
+
@session.driver.switch_to_frame(frame)
|
90
|
+
sleep 0.5
|
91
|
+
@session.driver.switch_to_frame(:parent)
|
92
|
+
}.not_to raise_error
|
93
|
+
end
|
52
94
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Capybara::SpecHelper.spec '#go_back', requires: [:js] do
|
2
3
|
it "should fetch a response from the driver from the previous page" do
|
3
4
|
@session.visit('/')
|
4
5
|
expect(@session).to have_content('Hello world!')
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Capybara::SpecHelper.spec '#go_forward', requires: [:js] do
|
2
3
|
it "should fetch a response from the driver from the previous page" do
|
3
4
|
@session.visit('/')
|
4
5
|
expect(@session).to have_content('Hello world!')
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Capybara::SpecHelper.spec '#have_all_selectors' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should be true if the given selectors are on the page" do
|
8
|
+
expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two" )
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be false if any of the given selectors are not on the page" do
|
12
|
+
expect {
|
13
|
+
expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")
|
14
|
+
}.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should use default selector" do
|
18
|
+
Capybara.default_selector = :css
|
19
|
+
expect(@session).to have_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one" )
|
20
|
+
expect {
|
21
|
+
expect(@session).to have_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")
|
22
|
+
}.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
23
|
+
end
|
24
|
+
|
25
|
+
context "should respect scopes" do
|
26
|
+
it "when used with `within`" do
|
27
|
+
@session.within "//p[@id='first']" do
|
28
|
+
expect(@session).to have_all_of_selectors(".//a[@id='foo']")
|
29
|
+
expect {
|
30
|
+
expect(@session).to have_all_of_selectors(".//a[@id='red']")
|
31
|
+
}.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "when called on elements" do
|
36
|
+
el = @session.find "//p[@id='first']"
|
37
|
+
expect(el).to have_all_of_selectors(".//a[@id='foo']")
|
38
|
+
expect {
|
39
|
+
expect(el).to have_all_of_selectors(".//a[@id='red']")
|
40
|
+
}.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with options" do
|
45
|
+
it "should apply options to all locators" do
|
46
|
+
expect(@session).to have_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
|
47
|
+
expect {
|
48
|
+
expect(@session).to have_all_of_selectors(:field, 'normal', 'test_field', 'additional_newline', type: :textarea)
|
49
|
+
}.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with wait", requires: [:js] do
|
54
|
+
it "should not raise error if all the elements appear before given wait duration" do
|
55
|
+
Capybara.using_wait_time(0.1) do
|
56
|
+
@session.visit('/with_js')
|
57
|
+
@session.click_link('Click me')
|
58
|
+
expect(@session).to have_all_of_selectors(:css, "a#clickable", "a#has-been-clicked", '#drag', wait: 0.9)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "cannot be negated" do
|
64
|
+
expect {
|
65
|
+
expect(@session).not_to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
|
66
|
+
}.to raise_error ArgumentError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#has_button?' do
|
2
3
|
before do
|
3
4
|
@session.visit('/form')
|
@@ -9,8 +10,8 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
9
10
|
expect(@session).to have_button(:'crap321')
|
10
11
|
end
|
11
12
|
|
12
|
-
it "should be true for disabled buttons if :
|
13
|
-
expect(@session).to have_button('Disabled button', :
|
13
|
+
it "should be true for disabled buttons if disabled: true" do
|
14
|
+
expect(@session).to have_button('Disabled button', disabled: true)
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should be false if the given button is not on the page" do
|
@@ -21,8 +22,16 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
21
22
|
expect(@session).not_to have_button('Disabled button')
|
22
23
|
end
|
23
24
|
|
24
|
-
it "should be false for disabled buttons if :
|
25
|
-
expect(@session).not_to have_button('Disabled button', :
|
25
|
+
it "should be false for disabled buttons if disabled: false" do
|
26
|
+
expect(@session).not_to have_button('Disabled button', disabled: false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be true for disabled buttons if disabled: :all" do
|
30
|
+
expect(@session).to have_button('Disabled button', disabled: :all)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be true for enabled buttons if disabled: :all" do
|
34
|
+
expect(@session).to have_button('med', disabled: :all)
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
@@ -36,8 +45,8 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
36
45
|
expect(@session).not_to have_no_button('crap321')
|
37
46
|
end
|
38
47
|
|
39
|
-
it "should be true for disabled buttons if :
|
40
|
-
expect(@session).not_to have_no_button('Disabled button', :
|
48
|
+
it "should be true for disabled buttons if disabled: true" do
|
49
|
+
expect(@session).not_to have_no_button('Disabled button', disabled: true)
|
41
50
|
end
|
42
51
|
|
43
52
|
it "should be false if the given button is not on the page" do
|
@@ -48,7 +57,7 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|
48
57
|
expect(@session).to have_no_button('Disabled button')
|
49
58
|
end
|
50
59
|
|
51
|
-
it "should be false for disabled buttons if :
|
52
|
-
expect(@session).to have_no_button('Disabled button', :
|
60
|
+
it "should be false for disabled buttons if disabled: false" do
|
61
|
+
expect(@session).to have_no_button('Disabled button', disabled: false)
|
53
62
|
end
|
54
63
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#has_css?' do
|
2
3
|
before do
|
3
4
|
@session.visit('/with_html')
|
@@ -21,7 +22,7 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
it "should wait for content to appear", :
|
25
|
+
it "should wait for content to appear", requires: [:js] do
|
25
26
|
@session.visit('/with_js')
|
26
27
|
@session.click_link('Click me')
|
27
28
|
expect(@session).to have_css("input[type='submit'][value='New Here']")
|
@@ -29,88 +30,99 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
29
30
|
|
30
31
|
context "with between" do
|
31
32
|
it "should be true if the content occurs within the range given" do
|
32
|
-
expect(@session).to have_css("p", :
|
33
|
-
expect(@session).to have_css("p a#foo", :
|
34
|
-
expect(@session).to have_css("p a.doesnotexist", :
|
33
|
+
expect(@session).to have_css("p", between: 1..4)
|
34
|
+
expect(@session).to have_css("p a#foo", between: 1..3)
|
35
|
+
expect(@session).to have_css("p a.doesnotexist", between: 0..8)
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should be false if the content occurs more or fewer times than range" do
|
38
|
-
expect(@session).not_to have_css("p", :
|
39
|
-
expect(@session).not_to have_css("p a#foo", :
|
40
|
-
expect(@session).not_to have_css("p a.doesnotexist", :
|
39
|
+
expect(@session).not_to have_css("p", between: 6..11 )
|
40
|
+
expect(@session).not_to have_css("p a#foo", between: 4..7)
|
41
|
+
expect(@session).not_to have_css("p a.doesnotexist", between: 3..8)
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
context "with count" do
|
45
46
|
it "should be true if the content occurs the given number of times" do
|
46
|
-
expect(@session).to have_css("p", :
|
47
|
-
expect(@session).to have_css("p a#foo", :
|
48
|
-
expect(@session).to have_css("p a.doesnotexist", :
|
47
|
+
expect(@session).to have_css("p", count: 3)
|
48
|
+
expect(@session).to have_css("p a#foo", count: 1)
|
49
|
+
expect(@session).to have_css("p a.doesnotexist", count: 0)
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should be false if the content occurs a different number of times than the given" do
|
52
|
-
expect(@session).not_to have_css("p", :
|
53
|
-
expect(@session).not_to have_css("p a#foo", :
|
54
|
-
expect(@session).not_to have_css("p a.doesnotexist", :
|
53
|
+
expect(@session).not_to have_css("p", count: 6)
|
54
|
+
expect(@session).not_to have_css("p a#foo", count: 2)
|
55
|
+
expect(@session).not_to have_css("p a.doesnotexist", count: 1)
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should coerce count to an integer" do
|
58
|
-
expect(@session).to have_css("p", :
|
59
|
-
expect(@session).to have_css("p a#foo", :
|
59
|
+
expect(@session).to have_css("p", count: "3")
|
60
|
+
expect(@session).to have_css("p a#foo", count: "1")
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
context "with maximum" do
|
64
65
|
it "should be true when content occurs same or fewer times than given" do
|
65
|
-
expect(@session).to have_css("h2.head", :
|
66
|
-
expect(@session).to have_css("h2", :
|
67
|
-
expect(@session).to have_css("p a.doesnotexist", :
|
68
|
-
expect(@session).to have_css("p a.doesnotexist", :
|
66
|
+
expect(@session).to have_css("h2.head", maximum: 5) # edge case
|
67
|
+
expect(@session).to have_css("h2", maximum: 10)
|
68
|
+
expect(@session).to have_css("p a.doesnotexist", maximum: 1)
|
69
|
+
expect(@session).to have_css("p a.doesnotexist", maximum: 0)
|
69
70
|
end
|
70
71
|
|
71
72
|
it "should be false when content occurs more times than given" do
|
72
|
-
expect(@session).not_to have_css("h2.head", :
|
73
|
-
expect(@session).not_to have_css("h2", :
|
74
|
-
expect(@session).not_to have_css("p", :
|
73
|
+
expect(@session).not_to have_css("h2.head", maximum: 4) # edge case
|
74
|
+
expect(@session).not_to have_css("h2", maximum: 3)
|
75
|
+
expect(@session).not_to have_css("p", maximum: 1)
|
75
76
|
end
|
76
77
|
|
77
78
|
it "should coerce maximum to an integer" do
|
78
|
-
expect(@session).to have_css("h2.head", :
|
79
|
-
expect(@session).to have_css("h2", :
|
79
|
+
expect(@session).to have_css("h2.head", maximum: "5") # edge case
|
80
|
+
expect(@session).to have_css("h2", maximum: "10")
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
84
|
context "with minimum" do
|
84
85
|
it "should be true when content occurs same or more times than given" do
|
85
|
-
expect(@session).to have_css("h2.head", :
|
86
|
-
expect(@session).to have_css("h2", :
|
87
|
-
expect(@session).to have_css("p a.doesnotexist", :
|
86
|
+
expect(@session).to have_css("h2.head", minimum: 5) # edge case
|
87
|
+
expect(@session).to have_css("h2", minimum: 3)
|
88
|
+
expect(@session).to have_css("p a.doesnotexist", minimum: 0)
|
88
89
|
end
|
89
90
|
|
90
91
|
it "should be false when content occurs fewer times than given" do
|
91
|
-
expect(@session).not_to have_css("h2.head", :
|
92
|
-
expect(@session).not_to have_css("h2", :
|
93
|
-
expect(@session).not_to have_css("p", :
|
94
|
-
expect(@session).not_to have_css("p a.doesnotexist", :
|
92
|
+
expect(@session).not_to have_css("h2.head", minimum: 6) # edge case
|
93
|
+
expect(@session).not_to have_css("h2", minimum: 8)
|
94
|
+
expect(@session).not_to have_css("p", minimum: 10)
|
95
|
+
expect(@session).not_to have_css("p a.doesnotexist", minimum: 1)
|
95
96
|
end
|
96
97
|
|
97
98
|
it "should coerce minimum to an integer" do
|
98
|
-
expect(@session).to have_css("h2.head", :
|
99
|
-
expect(@session).to have_css("h2", :
|
99
|
+
expect(@session).to have_css("h2.head", minimum: "5") # edge case
|
100
|
+
expect(@session).to have_css("h2", minimum: "3")
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
104
|
context "with text" do
|
104
105
|
it "should discard all matches where the given string is not contained" do
|
105
|
-
expect(@session).to have_css("p a", :
|
106
|
-
expect(@session).not_to have_css("p a", :
|
106
|
+
expect(@session).to have_css("p a", text: "Redirect", count: 1)
|
107
|
+
expect(@session).not_to have_css("p a", text: "Doesnotexist")
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should discard all matches where the given regexp is not matched" do
|
110
|
-
expect(@session).to have_css("p a", :
|
111
|
-
expect(@session).not_to have_css("p a", :
|
111
|
+
expect(@session).to have_css("p a", text: /re[dab]i/i, count: 1)
|
112
|
+
expect(@session).not_to have_css("p a", text: /Red$/)
|
112
113
|
end
|
113
114
|
end
|
115
|
+
|
116
|
+
it "should allow escapes in the CSS selector" do
|
117
|
+
if (defined?(TestClass) && @session.is_a?(TestClass)) || @session.driver.is_a?(Capybara::RackTest::Driver)
|
118
|
+
# Nokogiri doesn't unescape CSS selectors when converting from CSS to XPath
|
119
|
+
# See: https://github.com/teamcapybara/capybara/issues/1866
|
120
|
+
# Also: https://github.com/sparklemotion/nokogiri/pull/1646
|
121
|
+
pending "Current Nokogiri doesn't handle escapes in CSS attribute selectors correctly"
|
122
|
+
end
|
123
|
+
expect(@session).to have_css('p[data-random="abc\\\\def"]')
|
124
|
+
expect(@session).to have_css("p[data-random='#{Capybara::Selector::CSS.escape('abc\def')}']")
|
125
|
+
end
|
114
126
|
end
|
115
127
|
|
116
128
|
Capybara::SpecHelper.spec '#has_no_css?' do
|
@@ -136,7 +148,7 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|
136
148
|
end
|
137
149
|
end
|
138
150
|
|
139
|
-
it "should wait for content to disappear", :
|
151
|
+
it "should wait for content to disappear", requires: [:js] do
|
140
152
|
@session.visit('/with_js')
|
141
153
|
@session.click_link('Click me')
|
142
154
|
expect(@session).to have_no_css("p#change")
|
@@ -144,85 +156,85 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|
144
156
|
|
145
157
|
context "with between" do
|
146
158
|
it "should be false if the content occurs within the range given" do
|
147
|
-
expect(@session).not_to have_no_css("p", :
|
148
|
-
expect(@session).not_to have_no_css("p a#foo", :
|
149
|
-
expect(@session).not_to have_no_css("p a.doesnotexist", :
|
159
|
+
expect(@session).not_to have_no_css("p", between: 1..4)
|
160
|
+
expect(@session).not_to have_no_css("p a#foo", between: 1..3)
|
161
|
+
expect(@session).not_to have_no_css("p a.doesnotexist", between: 0..2)
|
150
162
|
end
|
151
163
|
|
152
164
|
it "should be true if the content occurs more or fewer times than range" do
|
153
|
-
expect(@session).to have_no_css("p", :
|
154
|
-
expect(@session).to have_no_css("p a#foo", :
|
155
|
-
expect(@session).to have_no_css("p a.doesnotexist", :
|
165
|
+
expect(@session).to have_no_css("p", between: 6..11 )
|
166
|
+
expect(@session).to have_no_css("p a#foo", between: 4..7)
|
167
|
+
expect(@session).to have_no_css("p a.doesnotexist", between: 3..8)
|
156
168
|
end
|
157
169
|
end
|
158
170
|
|
159
171
|
context "with count" do
|
160
172
|
it "should be false if the content is on the page the given number of times" do
|
161
|
-
expect(@session).not_to have_no_css("p", :
|
162
|
-
expect(@session).not_to have_no_css("p a#foo", :
|
163
|
-
expect(@session).not_to have_no_css("p a.doesnotexist", :
|
173
|
+
expect(@session).not_to have_no_css("p", count: 3)
|
174
|
+
expect(@session).not_to have_no_css("p a#foo", count: 1)
|
175
|
+
expect(@session).not_to have_no_css("p a.doesnotexist", count: 0)
|
164
176
|
end
|
165
177
|
|
166
178
|
it "should be true if the content is on the page the given number of times" do
|
167
|
-
expect(@session).to have_no_css("p", :
|
168
|
-
expect(@session).to have_no_css("p a#foo", :
|
169
|
-
expect(@session).to have_no_css("p a.doesnotexist", :
|
179
|
+
expect(@session).to have_no_css("p", count: 6)
|
180
|
+
expect(@session).to have_no_css("p a#foo", count: 2)
|
181
|
+
expect(@session).to have_no_css("p a.doesnotexist", count: 1)
|
170
182
|
end
|
171
183
|
|
172
184
|
it "should coerce count to an integer" do
|
173
|
-
expect(@session).not_to have_no_css("p", :
|
174
|
-
expect(@session).not_to have_no_css("p a#foo", :
|
185
|
+
expect(@session).not_to have_no_css("p", count: "3")
|
186
|
+
expect(@session).not_to have_no_css("p a#foo", count: "1")
|
175
187
|
end
|
176
188
|
end
|
177
189
|
|
178
190
|
context "with maximum" do
|
179
191
|
it "should be false when content occurs same or fewer times than given" do
|
180
|
-
expect(@session).not_to have_no_css("h2.head", :
|
181
|
-
expect(@session).not_to have_no_css("h2", :
|
182
|
-
expect(@session).not_to have_no_css("p a.doesnotexist", :
|
192
|
+
expect(@session).not_to have_no_css("h2.head", maximum: 5) # edge case
|
193
|
+
expect(@session).not_to have_no_css("h2", maximum: 10)
|
194
|
+
expect(@session).not_to have_no_css("p a.doesnotexist", maximum: 0)
|
183
195
|
end
|
184
196
|
|
185
197
|
it "should be true when content occurs more times than given" do
|
186
|
-
expect(@session).to have_no_css("h2.head", :
|
187
|
-
expect(@session).to have_no_css("h2", :
|
188
|
-
expect(@session).to have_no_css("p", :
|
198
|
+
expect(@session).to have_no_css("h2.head", maximum: 4) # edge case
|
199
|
+
expect(@session).to have_no_css("h2", maximum: 3)
|
200
|
+
expect(@session).to have_no_css("p", maximum: 1)
|
189
201
|
end
|
190
202
|
|
191
203
|
it "should coerce maximum to an integer" do
|
192
|
-
expect(@session).not_to have_no_css("h2.head", :
|
193
|
-
expect(@session).not_to have_no_css("h2", :
|
204
|
+
expect(@session).not_to have_no_css("h2.head", maximum: "5") # edge case
|
205
|
+
expect(@session).not_to have_no_css("h2", maximum: "10")
|
194
206
|
end
|
195
207
|
end
|
196
208
|
|
197
209
|
context "with minimum" do
|
198
210
|
it "should be false when content occurs same or more times than given" do
|
199
|
-
expect(@session).not_to have_no_css("h2.head", :
|
200
|
-
expect(@session).not_to have_no_css("h2", :
|
201
|
-
expect(@session).not_to have_no_css("p a.doesnotexist", :
|
211
|
+
expect(@session).not_to have_no_css("h2.head", minimum: 5) # edge case
|
212
|
+
expect(@session).not_to have_no_css("h2", minimum: 3)
|
213
|
+
expect(@session).not_to have_no_css("p a.doesnotexist", minimum: 0)
|
202
214
|
end
|
203
215
|
|
204
216
|
it "should be true when content occurs fewer times than given" do
|
205
|
-
expect(@session).to have_no_css("h2.head", :
|
206
|
-
expect(@session).to have_no_css("h2", :
|
207
|
-
expect(@session).to have_no_css("p", :
|
208
|
-
expect(@session).to have_no_css("p a.doesnotexist", :
|
217
|
+
expect(@session).to have_no_css("h2.head", minimum: 6) # edge case
|
218
|
+
expect(@session).to have_no_css("h2", minimum: 8)
|
219
|
+
expect(@session).to have_no_css("p", minimum: 15)
|
220
|
+
expect(@session).to have_no_css("p a.doesnotexist", minimum: 1)
|
209
221
|
end
|
210
222
|
|
211
223
|
it "should coerce minimum to an integer" do
|
212
|
-
expect(@session).not_to have_no_css("h2.head", :
|
213
|
-
expect(@session).not_to have_no_css("h2", :
|
224
|
+
expect(@session).not_to have_no_css("h2.head", minimum: "4") # edge case
|
225
|
+
expect(@session).not_to have_no_css("h2", minimum: "3")
|
214
226
|
end
|
215
227
|
end
|
216
228
|
|
217
229
|
context "with text" do
|
218
230
|
it "should discard all matches where the given string is not contained" do
|
219
|
-
expect(@session).not_to have_no_css("p a", :
|
220
|
-
expect(@session).to have_no_css("p a", :
|
231
|
+
expect(@session).not_to have_no_css("p a", text: "Redirect", count: 1)
|
232
|
+
expect(@session).to have_no_css("p a", text: "Doesnotexist")
|
221
233
|
end
|
222
234
|
|
223
235
|
it "should discard all matches where the given regexp is not matched" do
|
224
|
-
expect(@session).not_to have_no_css("p a", :
|
225
|
-
expect(@session).to have_no_css("p a", :
|
236
|
+
expect(@session).not_to have_no_css("p a", text: /re[dab]i/i, count: 1)
|
237
|
+
expect(@session).to have_no_css("p a", text: /Red$/)
|
226
238
|
end
|
227
239
|
end
|
228
240
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#has_current_path?' do
|
2
3
|
before do
|
3
4
|
@session.visit('/with_js')
|
@@ -12,9 +13,25 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
12
13
|
expect(@session).not_to have_current_path(/monkey/)
|
13
14
|
end
|
14
15
|
|
15
|
-
it "should
|
16
|
+
it "should not raise an error when non-http" do
|
17
|
+
@session.reset_session!
|
18
|
+
expect(@session.has_current_path?(/monkey/)).to eq false
|
19
|
+
expect(@session.has_current_path?("/with_js")).to eq false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should handle non-escaped query options" do
|
23
|
+
@session.click_link("Non-escaped query options")
|
24
|
+
expect(@session).to have_current_path("/with_html?options[]=things")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle escaped query options" do
|
28
|
+
@session.click_link("Escaped query options")
|
29
|
+
expect(@session).to have_current_path("/with_html?options%5B%5D=things")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should wait for current_path", requires: [:js] do
|
16
33
|
@session.click_link("Change page")
|
17
|
-
expect(@session).to have_current_path("/with_html")
|
34
|
+
expect(@session).to have_current_path("/with_html", wait: 3)
|
18
35
|
end
|
19
36
|
|
20
37
|
it "should be false if the page has not the given current_path" do
|
@@ -26,20 +43,66 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
26
43
|
expect(@session).to have_current_path('/with_js?test=test')
|
27
44
|
end
|
28
45
|
|
29
|
-
it "should compare the full url" do
|
46
|
+
it "should compare the full url if url: true is used" do
|
30
47
|
expect(@session).to have_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)
|
48
|
+
domain_port = if @session.respond_to?(:server) && @session.server
|
49
|
+
"#{@session.server.host}:#{@session.server.port}"
|
50
|
+
else
|
51
|
+
"www.example.com"
|
52
|
+
end
|
53
|
+
expect(@session).to have_current_path("http://#{domain_port}/with_js", url: true)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not compare the full url if url: true is not passed" do
|
57
|
+
expect(@session).to have_current_path(%r{^/with_js\Z})
|
58
|
+
expect(@session).to have_current_path('/with_js')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not compare the full url if url: false is passed" do
|
62
|
+
expect(@session).to have_current_path(%r{^/with_js\Z}, url: false)
|
63
|
+
expect(@session).to have_current_path('/with_js', url: false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should default to full url if value is a url" do
|
67
|
+
url = @session.current_url
|
68
|
+
expect(url).to match /with_js$/
|
69
|
+
expect(@session).to have_current_path(url)
|
70
|
+
expect(@session).not_to have_current_path("http://www.not_example.com/with_js")
|
31
71
|
end
|
32
72
|
|
33
73
|
it "should ignore the query" do
|
34
74
|
@session.visit('/with_js?test=test')
|
35
75
|
expect(@session).to have_current_path('/with_js?test=test')
|
36
76
|
expect(@session).to have_current_path('/with_js', only_path: true)
|
77
|
+
expect(@session).to have_current_path('/with_js', ignore_query: true)
|
78
|
+
uri = ::Addressable::URI.parse(@session.current_url)
|
79
|
+
uri.query = nil
|
80
|
+
expect(@session).to have_current_path(uri.to_s, ignore_query: true)
|
37
81
|
end
|
38
82
|
|
39
83
|
it "should not allow url and only_path at the same time" do
|
40
84
|
expect {
|
41
85
|
expect(@session).to have_current_path('/with_js', url: true, only_path: true)
|
42
|
-
|
86
|
+
}.to raise_error ArgumentError
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not raise an exception if the current_url is nil" do
|
90
|
+
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
91
|
+
|
92
|
+
# Without only_path option
|
93
|
+
expect {
|
94
|
+
expect(@session).to have_current_path(nil)
|
95
|
+
}.not_to raise_exception
|
96
|
+
|
97
|
+
# With only_path option
|
98
|
+
expect {
|
99
|
+
expect(@session).to have_current_path(nil, only_path: true)
|
100
|
+
}.not_to raise_exception
|
101
|
+
|
102
|
+
# With ignore_query option
|
103
|
+
expect {
|
104
|
+
expect(@session).to have_current_path(nil, ignore_query: true)
|
105
|
+
}.not_to raise_exception
|
43
106
|
end
|
44
107
|
end
|
45
108
|
|
@@ -57,12 +120,33 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|
57
120
|
expect(@session).to have_no_current_path(/monkey/)
|
58
121
|
end
|
59
122
|
|
60
|
-
it "should wait for current_path to disappear", :
|
61
|
-
|
62
|
-
|
123
|
+
it "should wait for current_path to disappear", requires: [:js] do
|
124
|
+
Capybara.using_wait_time(3) do
|
125
|
+
@session.click_link("Change page")
|
126
|
+
expect(@session).to have_no_current_path('/with_js')
|
127
|
+
end
|
63
128
|
end
|
64
129
|
|
65
130
|
it "should be true if the page has not the given current_path" do
|
66
131
|
expect(@session).to have_no_current_path('/with_html')
|
67
132
|
end
|
133
|
+
|
134
|
+
it "should not raise an exception if the current_url is nil" do
|
135
|
+
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
136
|
+
|
137
|
+
# Without only_path option
|
138
|
+
expect {
|
139
|
+
expect(@session).not_to have_current_path('/with_js')
|
140
|
+
}. not_to raise_exception
|
141
|
+
|
142
|
+
# With only_path option
|
143
|
+
expect {
|
144
|
+
expect(@session).not_to have_current_path('/with_js', only_path: true)
|
145
|
+
}. not_to raise_exception
|
146
|
+
|
147
|
+
# With ignore_query option
|
148
|
+
expect {
|
149
|
+
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
150
|
+
}. not_to raise_exception
|
151
|
+
end
|
68
152
|
end
|