capybara 2.15.0 → 3.0.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/History.md +137 -2
- data/README.md +36 -25
- data/lib/capybara/config.rb +11 -57
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +19 -16
- data/lib/capybara/driver/node.rb +5 -4
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +19 -29
- data/lib/capybara/minitest/spec.rb +16 -13
- data/lib/capybara/minitest.rb +140 -137
- data/lib/capybara/node/actions.rb +68 -89
- data/lib/capybara/node/base.rb +11 -18
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +8 -8
- data/lib/capybara/node/element.rb +32 -42
- data/lib/capybara/node/finders.rb +64 -71
- data/lib/capybara/node/matchers.rb +50 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +12 -8
- data/lib/capybara/queries/base_query.rb +22 -18
- data/lib/capybara/queries/current_path_query.rb +12 -25
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +100 -96
- data/lib/capybara/queries/sibling_query.rb +5 -5
- data/lib/capybara/queries/text_query.rb +35 -35
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +15 -18
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +6 -10
- data/lib/capybara/rack_test/form.rb +52 -39
- data/lib/capybara/rack_test/node.rb +93 -63
- data/lib/capybara/rails.rb +2 -6
- data/lib/capybara/result.rb +22 -22
- data/lib/capybara/rspec/compound.rb +5 -10
- data/lib/capybara/rspec/features.rb +17 -48
- data/lib/capybara/rspec/matcher_proxies.rb +31 -15
- data/lib/capybara/rspec/matchers.rb +116 -58
- data/lib/capybara/rspec.rb +5 -10
- data/lib/capybara/selector/css.rb +6 -11
- data/lib/capybara/selector/filter.rb +1 -17
- data/lib/capybara/selector/filter_set.rb +18 -15
- data/lib/capybara/selector/filters/base.rb +7 -6
- data/lib/capybara/selector/filters/expression_filter.rb +6 -23
- data/lib/capybara/selector/filters/node_filter.rb +2 -12
- data/lib/capybara/selector/selector.rb +28 -34
- data/lib/capybara/selector.rb +129 -117
- data/lib/capybara/selenium/driver.rb +172 -163
- data/lib/capybara/selenium/node.rb +218 -104
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session/config.rb +47 -59
- data/lib/capybara/session/matchers.rb +23 -14
- data/lib/capybara/session.rb +175 -229
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- data/lib/capybara/spec/public/test.js +38 -6
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +30 -1
- data/lib/capybara/spec/session/all_spec.rb +31 -18
- data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
- data/lib/capybara/spec/session/assert_current_path.rb +12 -11
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +31 -23
- data/lib/capybara/spec/session/assert_title.rb +13 -3
- data/lib/capybara/spec/session/attach_file_spec.rb +57 -29
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +7 -6
- data/lib/capybara/spec/session/choose_spec.rb +5 -4
- data/lib/capybara/spec/session/click_button_spec.rb +24 -32
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
- data/lib/capybara/spec/session/click_link_spec.rb +8 -7
- data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
- data/lib/capybara/spec/session/current_url_spec.rb +19 -8
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +5 -4
- data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
- data/lib/capybara/spec/session/find_button_spec.rb +4 -3
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
- data/lib/capybara/spec/session/find_field_spec.rb +9 -15
- data/lib/capybara/spec/session/find_link_spec.rb +6 -5
- data/lib/capybara/spec/session/find_spec.rb +37 -31
- data/lib/capybara/spec/session/first_spec.rb +60 -33
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_button_spec.rb +2 -1
- data/lib/capybara/spec/session/has_css_spec.rb +3 -2
- data/lib/capybara/spec/session/has_current_path_spec.rb +49 -22
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +5 -4
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -31
- data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
- data/lib/capybara/spec/session/has_table_spec.rb +2 -1
- data/lib/capybara/spec/session/has_text_spec.rb +9 -13
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +107 -58
- data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
- data/lib/capybara/spec/session/refresh_spec.rb +6 -2
- data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
- data/lib/capybara/spec/session/response_code.rb +1 -0
- 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 -11
- data/lib/capybara/spec/session/save_page_spec.rb +1 -17
- data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/select_spec.rb +21 -20
- data/lib/capybara/spec/session/selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/sibling_spec.rb +1 -1
- data/lib/capybara/spec/session/text_spec.rb +17 -3
- data/lib/capybara/spec/session/title_spec.rb +11 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
- data/lib/capybara/spec/session/unselect_spec.rb +7 -6
- data/lib/capybara/spec/session/visit_spec.rb +64 -3
- data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
- 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 +2 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +12 -12
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
- data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +36 -18
- data/lib/capybara/spec/test_app.rb +17 -9
- data/lib/capybara/spec/views/form.erb +7 -0
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +5 -0
- data/lib/capybara/spec/views/with_html.erb +27 -1
- data/lib/capybara/spec/views/with_js.erb +11 -0
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +6 -10
- data/lib/capybara.rb +29 -26
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +16 -69
- data/spec/dsl_spec.rb +5 -13
- data/spec/filter_set_spec.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
- data/spec/minitest_spec.rb +13 -4
- data/spec/minitest_spec_spec.rb +12 -3
- data/spec/per_session_config_spec.rb +9 -8
- data/spec/rack_test_spec.rb +21 -20
- data/spec/result_spec.rb +17 -16
- data/spec/rspec/features_spec.rb +17 -14
- data/spec/rspec/scenarios_spec.rb +5 -7
- data/spec/rspec/shared_spec_matchers.rb +96 -99
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_matchers_spec.rb +18 -2
- data/spec/rspec_spec.rb +11 -15
- data/spec/selector_spec.rb +5 -6
- data/spec/selenium_spec_chrome.rb +20 -11
- data/spec/selenium_spec_edge.rb +27 -0
- data/spec/selenium_spec_ie.rb +31 -0
- data/spec/selenium_spec_marionette.rb +38 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +82 -22
- data/spec/spec_helper.rb +3 -6
- metadata +76 -81
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#first' do
|
3
4
|
before do
|
4
5
|
@session.visit('/with_html')
|
@@ -9,8 +10,16 @@ Capybara::SpecHelper.spec '#first' do
|
|
9
10
|
expect(@session.first("//input[@id='test_field']").value).to eq('monkey')
|
10
11
|
end
|
11
12
|
|
12
|
-
it "should
|
13
|
-
expect
|
13
|
+
it "should raise ElementNotFound when nothing was found" do
|
14
|
+
expect do
|
15
|
+
@session.first('//div[@id="nosuchthing"]')
|
16
|
+
end.to raise_error Capybara::ElementNotFound
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil when nothing was found if count options allow no results" do
|
20
|
+
expect(@session.first('//div[@id="nosuchthing"]', minimum: 0)).to be_nil
|
21
|
+
expect(@session.first('//div[@id="nosuchthing"]', count: 0)).to be_nil
|
22
|
+
expect(@session.first('//div[@id="nosuchthing"]', between: (0..3))).to be_nil
|
14
23
|
end
|
15
24
|
|
16
25
|
it "should accept an XPath instance" do
|
@@ -20,9 +29,10 @@ Capybara::SpecHelper.spec '#first' do
|
|
20
29
|
expect(@session.first(@xpath).value).to eq('John')
|
21
30
|
end
|
22
31
|
|
23
|
-
it "should
|
24
|
-
|
25
|
-
|
32
|
+
it "should raise when unused parameters are passed" do
|
33
|
+
expect do
|
34
|
+
@session.first(:css, 'h1', 'unused text')
|
35
|
+
end.to raise_error ArgumentError, /Unused parameters passed.*unused text/
|
26
36
|
end
|
27
37
|
|
28
38
|
context "with css selectors" do
|
@@ -49,40 +59,52 @@ Capybara::SpecHelper.spec '#first' do
|
|
49
59
|
|
50
60
|
context "with visible filter" do
|
51
61
|
it "should only find visible nodes when true" do
|
52
|
-
expect
|
62
|
+
expect do
|
63
|
+
@session.first(:css, "a#invisible", visible: true)
|
64
|
+
end.to raise_error Capybara::ElementNotFound
|
53
65
|
end
|
54
66
|
|
55
67
|
it "should find nodes regardless of whether they are invisible when false" do
|
56
|
-
expect(@session.first(:css, "a#invisible", visible: false)).
|
57
|
-
expect(@session.first(:css, "a#invisible", visible: false, text: 'hidden link')).
|
58
|
-
expect(@session.first(:css, "a#visible", visible: false)).
|
68
|
+
expect(@session.first(:css, "a#invisible", visible: false)).to be
|
69
|
+
expect(@session.first(:css, "a#invisible", visible: false, text: 'hidden link')).to be
|
70
|
+
expect(@session.first(:css, "a#visible", visible: false)).to be
|
59
71
|
end
|
60
72
|
|
61
73
|
it "should find nodes regardless of whether they are invisible when :all" do
|
62
|
-
expect(@session.first(:css, "a#invisible", visible: :all)).
|
63
|
-
expect(@session.first(:css, "a#invisible", visible: :all, text: 'hidden link')).
|
64
|
-
expect(@session.first(:css, "a#visible", visible: :all)).
|
74
|
+
expect(@session.first(:css, "a#invisible", visible: :all)).to be
|
75
|
+
expect(@session.first(:css, "a#invisible", visible: :all, text: 'hidden link')).to be
|
76
|
+
expect(@session.first(:css, "a#visible", visible: :all)).to be
|
65
77
|
end
|
66
78
|
|
67
79
|
it "should find only hidden nodes when :hidden" do
|
68
|
-
expect(@session.first(:css, "a#invisible", visible: :hidden)).
|
69
|
-
expect(@session.first(:css, "a#invisible", visible: :hidden, text: 'hidden link')).
|
70
|
-
expect
|
71
|
-
|
80
|
+
expect(@session.first(:css, "a#invisible", visible: :hidden)).to be
|
81
|
+
expect(@session.first(:css, "a#invisible", visible: :hidden, text: 'hidden link')).to be
|
82
|
+
expect do
|
83
|
+
@session.first(:css, "a#invisible", visible: :hidden, text: 'not hidden link')
|
84
|
+
end.to raise_error Capybara::ElementNotFound
|
85
|
+
expect do
|
86
|
+
@session.first(:css, "a#visible", visible: :hidden)
|
87
|
+
end.to raise_error Capybara::ElementNotFound
|
72
88
|
end
|
73
89
|
|
74
90
|
it "should find only visible nodes when :visible" do
|
75
|
-
expect
|
76
|
-
|
77
|
-
|
91
|
+
expect do
|
92
|
+
@session.first(:css, "a#invisible", visible: :visible)
|
93
|
+
end.to raise_error Capybara::ElementNotFound
|
94
|
+
expect do
|
95
|
+
@session.first(:css, "a#invisible", visible: :visible, text: 'hidden link')
|
96
|
+
end.to raise_error Capybara::ElementNotFound
|
97
|
+
expect(@session.first(:css, "a#visible", visible: :visible)).to be
|
78
98
|
end
|
79
99
|
|
80
100
|
it "should default to Capybara.ignore_hidden_elements" do
|
81
101
|
Capybara.ignore_hidden_elements = true
|
82
|
-
expect
|
102
|
+
expect do
|
103
|
+
@session.first(:css, "a#invisible")
|
104
|
+
end.to raise_error Capybara::ElementNotFound
|
83
105
|
Capybara.ignore_hidden_elements = false
|
84
|
-
expect(@session.first(:css, "a#invisible")).
|
85
|
-
expect(@session.first(:css, "a")).
|
106
|
+
expect(@session.first(:css, "a#invisible")).to be
|
107
|
+
expect(@session.first(:css, "a")).to be
|
86
108
|
end
|
87
109
|
end
|
88
110
|
|
@@ -93,35 +115,40 @@ Capybara::SpecHelper.spec '#first' do
|
|
93
115
|
|
94
116
|
it "should find the first element using the given locator" do
|
95
117
|
@session.within(:xpath, "//div[@id='for_bar']") do
|
96
|
-
expect(@session.first('.//form')).
|
118
|
+
expect(@session.first('.//form')).to be
|
97
119
|
end
|
98
120
|
end
|
99
121
|
end
|
100
122
|
|
101
|
-
context "
|
123
|
+
context "waiting behavior", requires: [:js] do
|
102
124
|
before do
|
103
125
|
@session.visit('/with_js')
|
104
126
|
end
|
105
127
|
|
106
|
-
it "should not wait if
|
107
|
-
Capybara.wait_on_first_by_default = false
|
128
|
+
it "should not wait if minimum: 0" do
|
108
129
|
@session.click_link('clickable')
|
109
|
-
|
130
|
+
Capybara.using_wait_time(3) do
|
131
|
+
start_time = Time.now
|
132
|
+
expect(@session.first(:css, 'a#has-been-clicked', minimum: 0)).to be_nil
|
133
|
+
expect(Time.now - start_time).to be < 3
|
134
|
+
end
|
110
135
|
end
|
111
136
|
|
112
|
-
it "should wait for at least one match
|
113
|
-
Capybara.wait_on_first_by_default = true
|
137
|
+
it "should wait for at least one match by default" do
|
114
138
|
Capybara.using_wait_time(3) do
|
115
139
|
@session.click_link('clickable')
|
116
140
|
expect(@session.first(:css, 'a#has-been-clicked')).not_to be_nil
|
117
141
|
end
|
118
142
|
end
|
119
143
|
|
120
|
-
it "should
|
121
|
-
|
144
|
+
it "should raise an error after waiting if no match" do
|
145
|
+
@session.click_link('clickable')
|
122
146
|
Capybara.using_wait_time(3) do
|
123
|
-
|
124
|
-
expect
|
147
|
+
start_time = Time.now
|
148
|
+
expect do
|
149
|
+
@session.first(:css, 'a#not-a-real-link')
|
150
|
+
end.to raise_error Capybara::ElementNotFound
|
151
|
+
expect(Time.now - start_time).to be > 3
|
125
152
|
end
|
126
153
|
end
|
127
154
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#frame_title', requires: [:frames] do
|
4
|
+
before(:each) do
|
5
|
+
@session.visit('/within_frames')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the title in a frame" do
|
9
|
+
@session.within_frame("frameOne") do
|
10
|
+
expect(@session.driver.frame_title).to eq 'This is the title of frame one'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the title in FrameTwo" do
|
15
|
+
@session.within_frame("frameTwo") do
|
16
|
+
expect(@session.driver.frame_title).to eq 'This is the title of frame two'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return the title in the main frame" do
|
21
|
+
expect(@session.driver.frame_title).to eq 'With Frames'
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#frame_url', requires: [:frames] do
|
4
|
+
before(:each) do
|
5
|
+
@session.visit('/within_frames')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the url in a frame" do
|
9
|
+
@session.within_frame("frameOne") do
|
10
|
+
expect(@session.driver.frame_url).to end_with '/frame_one'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the url in FrameTwo" do
|
15
|
+
@session.within_frame("frameTwo") do
|
16
|
+
expect(@session.driver.frame_url).to end_with '/frame_two'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return the url in the main frame" do
|
21
|
+
expect(@session.driver.frame_url).to end_with('/within_frames')
|
22
|
+
end
|
23
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
|
3
4
|
before(:each) do
|
4
5
|
@session.visit('/within_frames')
|
@@ -47,7 +48,7 @@ Capybara::SpecHelper.spec '#switch_to_frame', requires: [:frames] do
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
it "works if the frame is closed", requires: [
|
51
|
+
it "works if the frame is closed", requires: %i[frames js] do
|
51
52
|
frame = @session.find(:frame, 'parentFrame')
|
52
53
|
@session.switch_to_frame frame
|
53
54
|
frame = @session.find(:frame, 'childFrame')
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
3
4
|
before(:each) do
|
4
5
|
@session.visit('/within_frames')
|
@@ -56,21 +57,25 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
|
56
57
|
it "should find multiple nested frames" do
|
57
58
|
@session.within_frame 'parentFrame' do
|
58
59
|
@session.within_frame 'childFrame' do
|
59
|
-
@session.within_frame 'grandchildFrame1' do
|
60
|
-
|
60
|
+
@session.within_frame 'grandchildFrame1' do
|
61
|
+
# dummy
|
62
|
+
end
|
63
|
+
@session.within_frame 'grandchildFrame2' do
|
64
|
+
# dummy
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
70
|
it "should reset scope when changing frames" do
|
66
71
|
@session.within(:css, '#divInMainWindow') do
|
67
|
-
@session.within_frame '
|
72
|
+
@session.within_frame 'innerParentFrame' do
|
68
73
|
expect(@session.has_selector?(:css, "iframe#childFrame")).to be true
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
|
73
|
-
it "works if the frame is closed", requires: [
|
78
|
+
it "works if the frame is closed", requires: %i[frames js] do
|
74
79
|
@session.within_frame 'parentFrame' do
|
75
80
|
@session.within_frame 'childFrame' do
|
76
81
|
@session.click_link 'Close Window'
|
@@ -79,16 +84,4 @@ Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
|
79
84
|
expect(@session).not_to have_selector(:css, '#childFrame')
|
80
85
|
end
|
81
86
|
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
|
94
87
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Capybara::SpecHelper.spec '#have_all_selectors' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be true if the given selectors are on the page" do
|
9
|
+
expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be false if any of the given selectors are not on the page" do
|
13
|
+
expect do
|
14
|
+
expect(@session).to have_all_of_selectors(:css, "p a#foo", "h2#h2three", "h2#h2one")
|
15
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should use default selector" do
|
19
|
+
Capybara.default_selector = :css
|
20
|
+
expect(@session).to have_all_of_selectors("p a#foo", "h2#h2two", "h2#h2one")
|
21
|
+
expect do
|
22
|
+
expect(@session).to have_all_of_selectors("p a#foo", "h2#h2three", "h2#h2one")
|
23
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
24
|
+
end
|
25
|
+
|
26
|
+
context "should respect scopes" do
|
27
|
+
it "when used with `within`" do
|
28
|
+
@session.within "//p[@id='first']" do
|
29
|
+
expect(@session).to have_all_of_selectors(".//a[@id='foo']")
|
30
|
+
expect do
|
31
|
+
expect(@session).to have_all_of_selectors(".//a[@id='red']")
|
32
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "when called on elements" do
|
37
|
+
el = @session.find "//p[@id='first']"
|
38
|
+
expect(el).to have_all_of_selectors(".//a[@id='foo']")
|
39
|
+
expect do
|
40
|
+
expect(el).to have_all_of_selectors(".//a[@id='red']")
|
41
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with options" do
|
46
|
+
it "should apply options to all locators" do
|
47
|
+
expect(@session).to have_all_of_selectors(:field, 'normal', 'additional_newline', type: :textarea)
|
48
|
+
expect do
|
49
|
+
expect(@session).to have_all_of_selectors(:field, 'normal', 'test_field', 'additional_newline', type: :textarea)
|
50
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with wait", requires: [:js] do
|
55
|
+
it "should not raise error if all the elements appear before given wait duration" do
|
56
|
+
Capybara.using_wait_time(0.1) do
|
57
|
+
@session.visit('/with_js')
|
58
|
+
@session.click_link('Click me')
|
59
|
+
expect(@session).to have_all_of_selectors(:css, "a#clickable", "a#has-been-clicked", '#drag', wait: 0.9)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "cannot be negated" do
|
65
|
+
expect do
|
66
|
+
expect(@session).not_to have_all_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
|
67
|
+
end.to raise_error ArgumentError
|
68
|
+
end
|
69
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#has_button?' do
|
3
4
|
before do
|
4
5
|
@session.visit('/form')
|
@@ -7,7 +8,7 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|
7
8
|
it "should be true if the given button is on the page" do
|
8
9
|
expect(@session).to have_button('med')
|
9
10
|
expect(@session).to have_button('crap321')
|
10
|
-
expect(@session).to have_button(:
|
11
|
+
expect(@session).to have_button(:crap321)
|
11
12
|
end
|
12
13
|
|
13
14
|
it "should be true for disabled buttons if disabled: true" do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#has_css?' do
|
3
4
|
before do
|
4
5
|
@session.visit('/with_html')
|
@@ -36,7 +37,7 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should be false if the content occurs more or fewer times than range" do
|
39
|
-
expect(@session).not_to have_css("p", between: 6..11
|
40
|
+
expect(@session).not_to have_css("p", between: 6..11)
|
40
41
|
expect(@session).not_to have_css("p a#foo", between: 4..7)
|
41
42
|
expect(@session).not_to have_css("p a.doesnotexist", between: 3..8)
|
42
43
|
end
|
@@ -162,7 +163,7 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|
162
163
|
end
|
163
164
|
|
164
165
|
it "should be true if the content occurs more or fewer times than range" do
|
165
|
-
expect(@session).to have_no_css("p", between: 6..11
|
166
|
+
expect(@session).to have_no_css("p", between: 6..11)
|
166
167
|
expect(@session).to have_no_css("p a#foo", between: 4..7)
|
167
168
|
expect(@session).to have_no_css("p a.doesnotexist", between: 3..8)
|
168
169
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#has_current_path?' do
|
3
4
|
before do
|
4
5
|
@session.visit('/with_js')
|
@@ -13,6 +14,12 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
13
14
|
expect(@session).not_to have_current_path(/monkey/)
|
14
15
|
end
|
15
16
|
|
17
|
+
it "should not raise an error when non-http" do
|
18
|
+
@session.reset_session!
|
19
|
+
expect(@session.has_current_path?(/monkey/)).to eq false
|
20
|
+
expect(@session.has_current_path?("/with_js")).to eq false
|
21
|
+
end
|
22
|
+
|
16
23
|
it "should handle non-escaped query options" do
|
17
24
|
@session.click_link("Non-escaped query options")
|
18
25
|
expect(@session).to have_current_path("/with_html?options[]=things")
|
@@ -37,34 +44,54 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
37
44
|
expect(@session).to have_current_path('/with_js?test=test')
|
38
45
|
end
|
39
46
|
|
40
|
-
it "should compare the full url" do
|
47
|
+
it "should compare the full url if url: true is used" do
|
41
48
|
expect(@session).to have_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)
|
49
|
+
domain_port = if @session.respond_to?(:server) && @session.server
|
50
|
+
"#{@session.server.host}:#{@session.server.port}"
|
51
|
+
else
|
52
|
+
"www.example.com"
|
53
|
+
end
|
54
|
+
expect(@session).to have_current_path("http://#{domain_port}/with_js", url: true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not compare the full url if url: true is not passed" do
|
58
|
+
expect(@session).to have_current_path(%r{^/with_js\Z})
|
59
|
+
expect(@session).to have_current_path('/with_js')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not compare the full url if url: false is passed" do
|
63
|
+
expect(@session).to have_current_path(%r{^/with_js\Z}, url: false)
|
64
|
+
expect(@session).to have_current_path('/with_js', url: false)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should default to full url if value is a url" do
|
68
|
+
url = @session.current_url
|
69
|
+
expect(url).to match(/with_js$/)
|
70
|
+
expect(@session).to have_current_path(url)
|
71
|
+
expect(@session).not_to have_current_path("http://www.not_example.com/with_js")
|
42
72
|
end
|
43
73
|
|
44
74
|
it "should ignore the query" do
|
45
75
|
@session.visit('/with_js?test=test')
|
46
76
|
expect(@session).to have_current_path('/with_js?test=test')
|
47
|
-
expect(@session).to have_current_path('/with_js',
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
expect {
|
52
|
-
expect(@session).to have_current_path('/with_js', url: true, only_path: true)
|
53
|
-
}. to raise_error ArgumentError
|
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)
|
54
81
|
end
|
55
82
|
|
56
83
|
it "should not raise an exception if the current_url is nil" do
|
57
84
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
58
85
|
|
59
|
-
# Without
|
60
|
-
expect
|
86
|
+
# Without ignore_query option
|
87
|
+
expect do
|
61
88
|
expect(@session).to have_current_path(nil)
|
62
|
-
|
89
|
+
end.not_to raise_exception
|
63
90
|
|
64
|
-
# With
|
65
|
-
expect
|
66
|
-
expect(@session).to have_current_path(nil,
|
67
|
-
|
91
|
+
# With ignore_query option
|
92
|
+
expect do
|
93
|
+
expect(@session).to have_current_path(nil, ignore_query: true)
|
94
|
+
end.not_to raise_exception
|
68
95
|
end
|
69
96
|
end
|
70
97
|
|
@@ -96,14 +123,14 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|
96
123
|
it "should not raise an exception if the current_url is nil" do
|
97
124
|
allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
|
98
125
|
|
99
|
-
# Without
|
100
|
-
expect
|
126
|
+
# Without ignore_query option
|
127
|
+
expect do
|
101
128
|
expect(@session).not_to have_current_path('/with_js')
|
102
|
-
|
129
|
+
end. not_to raise_exception
|
103
130
|
|
104
|
-
# With
|
105
|
-
expect
|
106
|
-
expect(@session).not_to have_current_path('/with_js',
|
107
|
-
|
131
|
+
# With ignore_query option
|
132
|
+
expect do
|
133
|
+
expect(@session).not_to have_current_path('/with_js', ignore_query: true)
|
134
|
+
end. not_to raise_exception
|
108
135
|
end
|
109
136
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#has_field' do
|
3
4
|
before { @session.visit('/form') }
|
4
5
|
|
@@ -6,7 +7,7 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
6
7
|
expect(@session).to have_field('Dog')
|
7
8
|
expect(@session).to have_field('form_description')
|
8
9
|
expect(@session).to have_field('Region')
|
9
|
-
expect(@session).to have_field(:
|
10
|
+
expect(@session).to have_field(:Region)
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should be false if the field is not on the page" do
|
@@ -269,7 +270,7 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
|
|
269
270
|
|
270
271
|
it "should support locator-less usage" do
|
271
272
|
expect(@session.has_unchecked_field?(disabled: true, id: "form_disabled_unchecked_checkbox"))
|
272
|
-
expect(@session).to have_unchecked_field(disabled: true, id: "form_disabled_unchecked_checkbox"
|
273
|
+
expect(@session).to have_unchecked_field(disabled: true, id: "form_disabled_unchecked_checkbox")
|
273
274
|
end
|
274
275
|
end
|
275
276
|
|
@@ -304,6 +305,6 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|
304
305
|
|
305
306
|
it "should support locator-less usage" do
|
306
307
|
expect(@session.has_no_unchecked_field?(disabled: false, id: "form_disabled_unchecked_checkbox")).to eq true
|
307
|
-
expect(@session).to have_no_unchecked_field(disabled: false, id: "form_disabled_unchecked_checkbox"
|
308
|
+
expect(@session).to have_no_unchecked_field(disabled: false, id: "form_disabled_unchecked_checkbox")
|
308
309
|
end
|
309
310
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Capybara::SpecHelper.spec '#has_link?' do
|
3
4
|
before do
|
4
5
|
@session.visit('/with_html')
|
@@ -14,8 +15,8 @@ Capybara::SpecHelper.spec '#has_link?' do
|
|
14
15
|
|
15
16
|
it "should be false if the given link is not on the page" do
|
16
17
|
expect(@session).not_to have_link('monkey')
|
17
|
-
expect(@session).not_to have_link('A link', href: '/
|
18
|
-
expect(@session).not_to have_link('A link', href: /
|
18
|
+
expect(@session).not_to have_link('A link', href: '/nonexistent-href')
|
19
|
+
expect(@session).not_to have_link('A link', href: /nonexistent/)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -32,7 +33,7 @@ Capybara::SpecHelper.spec '#has_no_link?' do
|
|
32
33
|
|
33
34
|
it "should be true if the given link is not on the page" do
|
34
35
|
expect(@session).to have_no_link('monkey')
|
35
|
-
expect(@session).to have_no_link('A link', href: '/
|
36
|
-
expect(@session).to have_no_link('A link', href: /\/
|
36
|
+
expect(@session).to have_no_link('A link', href: '/nonexistent-href')
|
37
|
+
expect(@session).to have_no_link('A link', href: /\/nonexistent-href/)
|
37
38
|
end
|
38
39
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
Capybara::SpecHelper.spec '#have_none_of_selectors' do
|
2
|
+
before do
|
3
|
+
@session.visit('/with_html')
|
4
|
+
end
|
5
|
+
|
6
|
+
it "should be false if any of the given locators are on the page" do
|
7
|
+
expect do
|
8
|
+
expect(@session).to have_none_of_selectors(:xpath, "//p", "//a")
|
9
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
10
|
+
expect do
|
11
|
+
expect(@session).to have_none_of_selectors(:css, "p a#foo")
|
12
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be true if none of the given locators are on the page" do
|
16
|
+
expect(@session).to have_none_of_selectors(:xpath, "//abbr", "//td")
|
17
|
+
expect(@session).to have_none_of_selectors(:css, "p a#doesnotexist", "abbr")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should use default selector" do
|
21
|
+
Capybara.default_selector = :css
|
22
|
+
expect(@session).to have_none_of_selectors("p a#doesnotexist", "abbr")
|
23
|
+
expect do
|
24
|
+
expect(@session).to have_none_of_selectors("abbr", "p a#foo")
|
25
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
26
|
+
end
|
27
|
+
|
28
|
+
context "should respect scopes" do
|
29
|
+
it "when used with `within`" do
|
30
|
+
@session.within "//p[@id='first']" do
|
31
|
+
expect do
|
32
|
+
expect(@session).to have_none_of_selectors(".//a[@id='foo']")
|
33
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
34
|
+
expect(@session).to have_none_of_selectors(".//a[@id='red']")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "when called on an element" do
|
39
|
+
el = @session.find "//p[@id='first']"
|
40
|
+
expect do
|
41
|
+
expect(el).to have_none_of_selectors(".//a[@id='foo']")
|
42
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
43
|
+
expect(el).to have_none_of_selectors(".//a[@id='red']")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with options" do
|
48
|
+
it "should apply the options to all locators" do
|
49
|
+
expect do
|
50
|
+
expect(@session).to have_none_of_selectors("//p//a", text: "Redirect")
|
51
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
52
|
+
expect(@session).to have_none_of_selectors("//p", text: "Doesnotexist")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should discard all matches where the given regexp is matched" do
|
56
|
+
expect do
|
57
|
+
expect(@session).to have_none_of_selectors("//p//a", text: /re[dab]i/i, count: 1)
|
58
|
+
end.to raise_error ::RSpec::Expectations::ExpectationNotMetError
|
59
|
+
expect(@session).to have_none_of_selectors("//p//a", text: /Red$/)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with wait", requires: [:js] do
|
64
|
+
it "should not find elements if they appear after given wait duration" do
|
65
|
+
@session.visit('/with_js')
|
66
|
+
@session.click_link('Click me')
|
67
|
+
expect(@session).to have_none_of_selectors(:css, "#new_field", "a#has-been-clicked", wait: 0.1)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "cannot be negated" do
|
72
|
+
expect do
|
73
|
+
expect(@session).not_to have_none_of_selectors(:css, "p a#foo", "h2#h2one", "h2#h2two")
|
74
|
+
end.to raise_error ArgumentError
|
75
|
+
end
|
76
|
+
end
|