capybara 2.18.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 +4 -4
- data/History.md +55 -1
- data/README.md +18 -17
- data/lib/capybara/config.rb +11 -58
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +15 -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 +15 -14
- data/lib/capybara/minitest.rb +139 -138
- data/lib/capybara/node/actions.rb +60 -81
- 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 +30 -40
- data/lib/capybara/node/finders.rb +62 -70
- data/lib/capybara/node/matchers.rb +50 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +11 -7
- data/lib/capybara/queries/base_query.rb +22 -18
- data/lib/capybara/queries/current_path_query.rb +8 -24
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +92 -95
- data/lib/capybara/queries/sibling_query.rb +4 -4
- 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 +50 -40
- 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 +70 -61
- 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 +131 -125
- data/lib/capybara/selenium/node.rb +197 -115
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session/config.rb +47 -67
- data/lib/capybara/session/matchers.rb +8 -7
- data/lib/capybara/session.rb +138 -224
- data/lib/capybara/spec/public/test.js +25 -4
- 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 +1 -0
- 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 +23 -23
- data/lib/capybara/spec/session/assert_title.rb +13 -3
- data/lib/capybara/spec/session/attach_file_spec.rb +51 -30
- 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 +17 -6
- 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 +3 -2
- data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
- 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 +15 -15
- 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 +12 -28
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +1 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_select_spec.rb +30 -29
- 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 +91 -56
- 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 +20 -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 +6 -5
- data/lib/capybara/spec/session/visit_spec.rb +9 -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 +34 -18
- data/lib/capybara/spec/test_app.rb +17 -9
- data/lib/capybara/spec/views/form.erb +7 -0
- data/lib/capybara/spec/views/with_html.erb +23 -1
- 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 +28 -25
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +11 -50
- 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 +4 -3
- data/spec/minitest_spec_spec.rb +3 -2
- 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 +9 -4
- data/spec/selenium_spec_edge.rb +27 -0
- data/spec/selenium_spec_ie.rb +31 -0
- data/spec/selenium_spec_marionette.rb +28 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +36 -22
- data/spec/spec_helper.rb +3 -6
- metadata +68 -85
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/dsl'
|
4
5
|
require 'capybara/rspec/matchers'
|
5
6
|
require 'benchmark'
|
6
7
|
|
7
|
-
RSpec.shared_examples Capybara::RSpecMatchers do |session,
|
8
|
-
|
8
|
+
RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
9
9
|
include Capybara::DSL
|
10
10
|
include Capybara::RSpecMatchers
|
11
11
|
|
@@ -53,7 +53,6 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
53
53
|
expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
|
54
54
|
end.to raise_error("expected to find visible css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
|
55
55
|
end
|
56
|
-
|
57
56
|
end
|
58
57
|
|
59
58
|
context "with should_not" do
|
@@ -81,7 +80,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
81
80
|
it "supports compounding" do
|
82
81
|
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
|
83
82
|
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
|
84
|
-
end
|
83
|
+
end
|
85
84
|
end
|
86
85
|
|
87
86
|
context "on a page or node" do
|
@@ -129,7 +128,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
129
128
|
it "fails if has_xpath? returns false" do
|
130
129
|
expect do
|
131
130
|
expect("<h1>Text</h1>").to have_xpath('//h2')
|
132
|
-
end.to raise_error(%r
|
131
|
+
end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
|
133
132
|
end
|
134
133
|
end
|
135
134
|
|
@@ -141,14 +140,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
141
140
|
it "fails if has_no_xpath? returns false" do
|
142
141
|
expect do
|
143
142
|
expect("<h1>Text</h1>").not_to have_xpath('//h1')
|
144
|
-
end.to raise_error(%r
|
143
|
+
end.to raise_error(%r{expected not to find visible xpath "//h1"})
|
145
144
|
end
|
146
145
|
end
|
147
146
|
|
148
147
|
it "supports compounding" do
|
149
148
|
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
|
150
149
|
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
|
151
|
-
end
|
150
|
+
end
|
152
151
|
end
|
153
152
|
|
154
153
|
context "on a page or node" do
|
@@ -164,7 +163,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
164
163
|
it "fails if has_xpath? returns false" do
|
165
164
|
expect do
|
166
165
|
expect(page).to have_xpath("//h1[@id='doesnotexist']")
|
167
|
-
end.to raise_error(%r
|
166
|
+
end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
|
168
167
|
end
|
169
168
|
end
|
170
169
|
|
@@ -176,7 +175,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
176
175
|
it "fails if has_no_xpath? returns false" do
|
177
176
|
expect do
|
178
177
|
expect(page).not_to have_xpath('//h1')
|
179
|
-
end.to raise_error(%r
|
178
|
+
end.to raise_error(%r{expected not to find visible xpath "//h1"})
|
180
179
|
end
|
181
180
|
end
|
182
181
|
end
|
@@ -198,7 +197,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
198
197
|
it "fails if has_selector? returns false" do
|
199
198
|
expect do
|
200
199
|
expect("<h1>Text</h1>").to have_selector('//h2')
|
201
|
-
end.to raise_error(%r
|
200
|
+
end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
|
202
201
|
end
|
203
202
|
end
|
204
203
|
|
@@ -210,7 +209,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
210
209
|
it "fails if has_no_selector? returns false" do
|
211
210
|
expect do
|
212
211
|
expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
|
213
|
-
end.to raise_error(%r
|
212
|
+
end.to raise_error(%r{expected not to find visible css "h1"})
|
214
213
|
end
|
215
214
|
end
|
216
215
|
end
|
@@ -228,13 +227,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
228
227
|
it "fails if has_selector? returns false" do
|
229
228
|
expect do
|
230
229
|
expect(page).to have_selector("//h1[@id='doesnotexist']")
|
231
|
-
end.to raise_error(%r
|
230
|
+
end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
|
232
231
|
end
|
233
232
|
|
234
233
|
it "includes text in error message" do
|
235
234
|
expect do
|
236
235
|
expect(page).to have_selector("//h1", text: 'wrong text')
|
237
|
-
end.to raise_error(%r
|
236
|
+
end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
|
238
237
|
end
|
239
238
|
end
|
240
239
|
|
@@ -246,7 +245,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
246
245
|
it "fails if has_no_selector? returns false" do
|
247
246
|
expect do
|
248
247
|
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
249
|
-
end.to raise_error(%r
|
248
|
+
end.to raise_error(%r{expected not to find visible css "h1" with text "test"})
|
250
249
|
end
|
251
250
|
end
|
252
251
|
end
|
@@ -254,7 +253,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
254
253
|
it "supports compounding" do
|
255
254
|
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
|
256
255
|
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
|
257
|
-
end
|
256
|
+
end
|
258
257
|
end
|
259
258
|
|
260
259
|
describe "have_content matcher" do
|
@@ -343,7 +342,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
343
342
|
it "supports compounding" do
|
344
343
|
expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
|
345
344
|
expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
|
346
|
-
end
|
345
|
+
end
|
347
346
|
end
|
348
347
|
|
349
348
|
describe "have_text matcher" do
|
@@ -477,7 +476,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
477
476
|
it "supports compounding" do
|
478
477
|
expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
|
479
478
|
expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
|
480
|
-
end
|
479
|
+
end
|
481
480
|
end
|
482
481
|
|
483
482
|
describe "have_link matcher" do
|
@@ -500,7 +499,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
500
499
|
it "supports compounding" do
|
501
500
|
expect(html).to have_link('Just a link').and have_link('Another link')
|
502
501
|
expect(html).to have_link('Not a link').or have_link('Another link')
|
503
|
-
end
|
502
|
+
end
|
504
503
|
end
|
505
504
|
|
506
505
|
describe "have_title matcher" do
|
@@ -565,7 +564,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
565
564
|
|
566
565
|
it "supports compounding" do
|
567
566
|
expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
|
568
|
-
end
|
567
|
+
end
|
569
568
|
end
|
570
569
|
|
571
570
|
describe "have_current_path matcher" do
|
@@ -611,7 +610,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
611
610
|
it "supports compounding" do
|
612
611
|
visit('/with_html')
|
613
612
|
expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
|
614
|
-
end
|
613
|
+
end
|
615
614
|
end
|
616
615
|
|
617
616
|
describe "have_button matcher" do
|
@@ -633,7 +632,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
633
632
|
|
634
633
|
it "supports compounding" do
|
635
634
|
expect(html).to have_button('Not this button').or have_button('A button')
|
636
|
-
end
|
635
|
+
end
|
637
636
|
end
|
638
637
|
|
639
638
|
describe "have_field matcher" do
|
@@ -678,7 +677,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
678
677
|
|
679
678
|
it "supports compounding" do
|
680
679
|
expect(html).to have_field('Not this one').or have_field('Text field')
|
681
|
-
end
|
680
|
+
end
|
682
681
|
end
|
683
682
|
|
684
683
|
describe "have_checked_field matcher" do
|
@@ -727,7 +726,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
727
726
|
|
728
727
|
it "supports compounding" do
|
729
728
|
expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
|
730
|
-
end
|
729
|
+
end
|
731
730
|
end
|
732
731
|
|
733
732
|
describe "have_unchecked_field matcher" do
|
@@ -776,7 +775,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
776
775
|
|
777
776
|
it "supports compounding" do
|
778
777
|
expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
|
779
|
-
end
|
778
|
+
end
|
780
779
|
end
|
781
780
|
|
782
781
|
describe "have_select matcher" do
|
@@ -802,7 +801,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
802
801
|
|
803
802
|
it "supports compounding" do
|
804
803
|
expect(html).to have_select('Not this one').or have_select('Select Box')
|
805
|
-
end
|
804
|
+
end
|
806
805
|
end
|
807
806
|
|
808
807
|
describe "have_table matcher" do
|
@@ -831,100 +830,98 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
|
|
831
830
|
|
832
831
|
it "supports compounding" do
|
833
832
|
expect(html).to have_table('nope').or have_table('Lovely table')
|
834
|
-
end
|
833
|
+
end
|
835
834
|
end
|
836
835
|
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
end
|
844
|
-
|
845
|
-
context "#and" do
|
846
|
-
it "should run 'concurrently'" do
|
847
|
-
Capybara.using_wait_time(2) do
|
848
|
-
matcher = have_text('this is not there').and have_text('neither is this')
|
849
|
-
expect(Benchmark.realtime do
|
850
|
-
expect {
|
851
|
-
expect(@el).to matcher
|
852
|
-
}.to raise_error RSpec::Expectations::ExpectationNotMetError
|
853
|
-
end).to be_between(2,3)
|
854
|
-
end
|
855
|
-
end
|
836
|
+
context "compounding", requires: [:js] do
|
837
|
+
before(:each) do
|
838
|
+
@session = session
|
839
|
+
@session.visit('/with_js')
|
840
|
+
@el = @session.find(:css, '#reload-me')
|
841
|
+
end
|
856
842
|
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
end
|
865
|
-
end
|
843
|
+
context "#and" do
|
844
|
+
it "should run 'concurrently'" do
|
845
|
+
Capybara.using_wait_time(2) do
|
846
|
+
matcher = have_text('this is not there').and have_text('neither is this')
|
847
|
+
expect(Benchmark.realtime do
|
848
|
+
expect do
|
849
|
+
expect(@el).to matcher
|
850
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
851
|
+
end).to be_between(2, 3)
|
866
852
|
end
|
853
|
+
end
|
867
854
|
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
end
|
855
|
+
it "should run 'concurrently' and retry" do
|
856
|
+
@session.click_link('reload-link')
|
857
|
+
@session.using_wait_time(2) do
|
858
|
+
expect(Benchmark.realtime do
|
859
|
+
expect do
|
860
|
+
expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
|
861
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
|
862
|
+
end).to be_between(2, 3)
|
877
863
|
end
|
864
|
+
end
|
878
865
|
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
866
|
+
it "should ignore :wait options" do
|
867
|
+
@session.using_wait_time(2) do
|
868
|
+
matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
|
869
|
+
expect(Benchmark.realtime do
|
870
|
+
expect do
|
871
|
+
expect(@el).to matcher
|
872
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
873
|
+
end).to be_between(2, 3)
|
884
874
|
end
|
885
875
|
end
|
886
876
|
|
887
|
-
|
888
|
-
|
877
|
+
it "should work on the session" do
|
878
|
+
@session.using_wait_time(2) do
|
889
879
|
@session.click_link('reload-link')
|
890
|
-
expect(@
|
880
|
+
expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
|
891
881
|
end
|
892
882
|
end
|
883
|
+
end
|
893
884
|
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
885
|
+
context "#and_then" do
|
886
|
+
it "should run sequentially" do
|
887
|
+
@session.click_link('reload-link')
|
888
|
+
expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
|
889
|
+
end
|
890
|
+
end
|
891
|
+
|
892
|
+
context "#or" do
|
893
|
+
it "should run 'concurrently'" do
|
894
|
+
@session.using_wait_time(3) do
|
895
|
+
expect(Benchmark.realtime do
|
896
|
+
expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
|
897
|
+
end).to be < 1
|
901
898
|
end
|
899
|
+
end
|
902
900
|
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
end
|
901
|
+
it "should retry" do
|
902
|
+
@session.using_wait_time(3) do
|
903
|
+
expect(Benchmark.realtime do
|
904
|
+
expect do
|
905
|
+
expect(@el).to have_text('has been reloaded').or have_text('random stuff')
|
906
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
907
|
+
end).to be > 3
|
911
908
|
end
|
909
|
+
end
|
912
910
|
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
end
|
911
|
+
it "should ignore :wait options" do
|
912
|
+
@session.using_wait_time(2) do
|
913
|
+
expect(Benchmark.realtime do
|
914
|
+
expect do
|
915
|
+
expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
|
916
|
+
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
917
|
+
end).to be_between(2, 3)
|
921
918
|
end
|
919
|
+
end
|
922
920
|
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
end
|
921
|
+
it "should work on the session" do
|
922
|
+
@session.using_wait_time(2) do
|
923
|
+
@session.click_link('reload-link')
|
924
|
+
expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
|
928
925
|
end
|
929
926
|
end
|
930
927
|
end
|
data/spec/rspec/views_spec.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe "capybara/rspec", type: :view do
|
5
6
|
it "allows matchers to be used on strings" do
|
6
|
-
expect(%
|
7
|
+
expect(%(<h1>Test header</h1>)).to have_css("h1", text: "Test header")
|
7
8
|
end
|
8
9
|
|
9
10
|
it "doesn't include RSpecMatcherProxies" do
|
data/spec/rspec_matchers_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
RSpec.describe 'Capybara RSpec Matchers', :
|
5
|
+
RSpec.describe 'Capybara RSpec Matchers', type: :feature do
|
5
6
|
context "after called on session" do
|
6
7
|
it "HaveSelector should allow getting a description of the matcher" do
|
7
8
|
visit('/with_html')
|
@@ -16,6 +17,17 @@ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
|
|
16
17
|
expect(page).to matcher
|
17
18
|
expect { matcher.description }.not_to raise_error
|
18
19
|
end
|
20
|
+
|
21
|
+
it "should produce the same error for .to have_no_xxx and .not_to have_xxx" do
|
22
|
+
visit('/with_html')
|
23
|
+
not_to_msg = error_msg_for { expect(page).not_to have_selector(:css, '#referrer') }
|
24
|
+
have_no_msg = error_msg_for { expect(page).to have_no_selector(:css, '#referrer') }
|
25
|
+
expect(not_to_msg).to eq have_no_msg
|
26
|
+
|
27
|
+
not_to_msg = error_msg_for { expect(page).not_to have_text('This is a test') }
|
28
|
+
have_no_msg = error_msg_for { expect(page).to have_no_text('This is a test') }
|
29
|
+
expect(not_to_msg).to eq have_no_msg
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
context "after called on element" do
|
@@ -43,4 +55,8 @@ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
|
|
43
55
|
expect { matcher.description }.not_to raise_error
|
44
56
|
end
|
45
57
|
end
|
46
|
-
|
58
|
+
|
59
|
+
def error_msg_for(&block)
|
60
|
+
expect(&block).to(raise_error { |e| return e.message })
|
61
|
+
end
|
62
|
+
end
|
data/spec/rspec_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
RSpec.describe 'capybara/rspec', :
|
5
|
+
RSpec.describe 'capybara/rspec', type: :feature do
|
5
6
|
it "should include Capybara in rspec" do
|
6
7
|
visit('/foo')
|
7
8
|
expect(page.body).to include('Another World')
|
@@ -37,21 +38,20 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
37
38
|
expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
|
38
39
|
end
|
39
40
|
|
40
|
-
it "switches to the given driver when giving it as metadata", :
|
41
|
+
it "switches to the given driver when giving it as metadata", driver: :culerity do
|
41
42
|
expect(Capybara.current_driver).to eq(:culerity)
|
42
43
|
end
|
43
44
|
|
44
45
|
context "#all" do
|
45
46
|
it "allows access to the Capybara finder" do
|
46
47
|
visit('/with_html')
|
47
|
-
|
48
|
+
found = all(:css, 'h2') { |element| element[:class] == 'head' }
|
49
|
+
expect(found.size).to eq(5)
|
48
50
|
end
|
49
51
|
|
50
52
|
it "allows access to the RSpec matcher" do
|
51
|
-
skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
|
52
|
-
|
53
53
|
visit('/with_html')
|
54
|
-
expect([
|
54
|
+
expect(%w[test1 test2]).to all(be_a(String))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -64,7 +64,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "allows access to the RSpec matcher" do
|
67
|
-
skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
|
68
67
|
visit('/with_html')
|
69
68
|
# This reads terribly, but must call #within
|
70
69
|
expect(find(:css, 'span.number').text.to_i).to within(1).of(41)
|
@@ -72,15 +71,15 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
|
-
RSpec.describe 'capybara/rspec', :
|
74
|
+
RSpec.describe 'capybara/rspec', type: :other do
|
76
75
|
context "when RSpec::Matchers is included after Capybara::DSL" do
|
77
76
|
before do
|
78
|
-
class
|
77
|
+
class DSLMatchersTest
|
79
78
|
include Capybara::DSL
|
80
79
|
include RSpec::Matchers
|
81
80
|
end
|
82
81
|
|
83
|
-
@test_class_instance =
|
82
|
+
@test_class_instance = DSLMatchersTest.new
|
84
83
|
end
|
85
84
|
|
86
85
|
context "#all" do
|
@@ -90,10 +89,8 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
90
89
|
end
|
91
90
|
|
92
91
|
it "allows access to the RSpec matcher" do
|
93
|
-
skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
|
94
|
-
|
95
92
|
@test_class_instance.visit('/with_html')
|
96
|
-
expect([
|
93
|
+
expect(%w[test1 test2]).to @test_class_instance.all(be_a(String))
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
@@ -106,7 +103,6 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
106
103
|
end
|
107
104
|
|
108
105
|
it "allows access to the RSpec matcher" do
|
109
|
-
skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
|
110
106
|
@test_class_instance.visit('/with_html')
|
111
107
|
# This reads terribly, but must call #within
|
112
108
|
expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41)
|
@@ -115,7 +111,7 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
118
|
-
RSpec.describe 'capybara/rspec', :
|
114
|
+
RSpec.describe 'capybara/rspec', type: :other do
|
119
115
|
it "should not include Capybara" do
|
120
116
|
expect { visit('/') }.to raise_error(NoMethodError)
|
121
117
|
end
|
data/spec/selector_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara do
|
@@ -56,7 +57,7 @@ RSpec.describe Capybara do
|
|
56
57
|
it "can set default visiblity" do
|
57
58
|
Capybara.add_selector :hidden_field do
|
58
59
|
visible :hidden
|
59
|
-
css { |
|
60
|
+
css { |_sel| 'input[type="hidden"]' }
|
60
61
|
end
|
61
62
|
|
62
63
|
expect(string).to have_no_css('input[type="hidden"]')
|
@@ -77,7 +78,7 @@ RSpec.describe Capybara do
|
|
77
78
|
|
78
79
|
it "doesn't change existing filters" do
|
79
80
|
Capybara.modify_selector :custom_selector do
|
80
|
-
css { |css_class| "p.#{css_class}"}
|
81
|
+
css { |css_class| "p.#{css_class}" }
|
81
82
|
end
|
82
83
|
expect(string).to have_selector(:custom_selector, 'b', count: 1)
|
83
84
|
expect(string).to have_selector(:custom_selector, 'b', not_empty: false, count: 1)
|
@@ -92,7 +93,7 @@ RSpec.describe Capybara do
|
|
92
93
|
field: ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]",
|
93
94
|
fieldset: ".//fieldset",
|
94
95
|
link: ".//a[./@href]",
|
95
|
-
link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button"
|
96
|
+
link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button",
|
96
97
|
fillable_field: ".//*[self::input | self::textarea][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'radio' or ./@type = 'checkbox' or ./@type = 'hidden' or ./@type = 'file')]",
|
97
98
|
radio_button: ".//input[./@type = 'radio']",
|
98
99
|
checkbox: ".//input[./@type = 'checkbox']",
|
@@ -102,7 +103,7 @@ RSpec.describe Capybara do
|
|
102
103
|
table: ".//table"
|
103
104
|
}
|
104
105
|
selectors.each do |selector, xpath|
|
105
|
-
results = string.all(selector,nil).to_a.map(&:native)
|
106
|
+
results = string.all(selector, nil).to_a.map(&:native)
|
106
107
|
expect(results.size).to be > 0
|
107
108
|
expect(results).to eq string.all(:xpath, xpath).to_a.map(&:native)
|
108
109
|
end
|
@@ -116,7 +117,6 @@ RSpec.describe Capybara do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it "works with 'special' characters" do
|
119
|
-
skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
|
120
120
|
expect(string.find(:custom_css_selector, "div", id: "#special")[:id]).to eq '#special'
|
121
121
|
expect(string.find(:custom_css_selector, "input", id: "2checkbox")[:id]).to eq '2checkbox'
|
122
122
|
end
|
@@ -129,7 +129,6 @@ RSpec.describe Capybara do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "works with 'special' characters" do
|
132
|
-
skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
|
133
132
|
expect(string.find(:custom_css_selector, "input", class: ".special")[:id]).to eq 'file'
|
134
133
|
expect(string.find(:custom_css_selector, "input", class: "2checkbox")[:id]).to eq '2checkbox'
|
135
134
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'selenium-webdriver'
|
4
5
|
require 'shared_selenium_session'
|
6
|
+
require 'rspec/shared_spec_matchers'
|
5
7
|
|
6
|
-
CHROME_DRIVER =
|
8
|
+
CHROME_DRIVER = ENV['HEADLESS'] ? :selenium_chrome_headless : :selenium_chrome
|
7
9
|
|
8
10
|
# if ENV['HEADLESS'] && ENV['TRAVIS']
|
9
11
|
# Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
|
@@ -12,7 +14,7 @@ CHROME_DRIVER = if ENV['HEADLESS'] then :selenium_chrome_headless else :selenium
|
|
12
14
|
Capybara.register_driver :selenium_chrome_clear_storage do |app|
|
13
15
|
chrome_options = {
|
14
16
|
browser: :chrome,
|
15
|
-
options: ::Selenium::WebDriver::Chrome::Options.new
|
17
|
+
options: ::Selenium::WebDriver::Chrome::Options.new
|
16
18
|
}
|
17
19
|
chrome_options[:options].args << 'headless' if ENV['HEADLESS']
|
18
20
|
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: true, clear_session_storage: true))
|
@@ -22,15 +24,18 @@ module TestSessions
|
|
22
24
|
Chrome = Capybara::Session.new(CHROME_DRIVER, TestApp)
|
23
25
|
end
|
24
26
|
|
25
|
-
skipped_tests = [
|
27
|
+
skipped_tests = %i[response_headers status_code trigger]
|
26
28
|
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
|
27
|
-
skipped_tests << :windows if ENV['TRAVIS']
|
29
|
+
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
|
30
|
+
|
31
|
+
$stdout.puts `#{Selenium::WebDriver::Chrome.driver_path} --version` if ENV['CI']
|
28
32
|
|
29
33
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests
|
30
34
|
|
31
35
|
RSpec.describe "Capybara::Session with chrome" do
|
32
36
|
include Capybara::SpecHelper
|
33
37
|
include_examples "Capybara::Session", TestSessions::Chrome, CHROME_DRIVER
|
38
|
+
include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_DRIVER
|
34
39
|
|
35
40
|
context "storage" do
|
36
41
|
describe "#reset!" do
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "selenium-webdriver"
|
5
|
+
require 'shared_selenium_session'
|
6
|
+
require 'rspec/shared_spec_matchers'
|
7
|
+
|
8
|
+
Capybara.register_driver :selenium_edge do |app|
|
9
|
+
# ::Selenium::WebDriver.logger.level = "debug"
|
10
|
+
Capybara::Selenium::Driver.new(app, browser: :edge)
|
11
|
+
end
|
12
|
+
|
13
|
+
module TestSessions
|
14
|
+
SeleniumEdge = Capybara::Session.new(:selenium_edge, TestApp)
|
15
|
+
end
|
16
|
+
|
17
|
+
skipped_tests = %i[response_headers status_code trigger modals]
|
18
|
+
|
19
|
+
$stdout.puts `#{Selenium::WebDriver::Edge.driver_path} --version` if ENV['CI']
|
20
|
+
|
21
|
+
Capybara::SpecHelper.run_specs TestSessions::SeleniumEdge, "selenium", capybara_skip: skipped_tests
|
22
|
+
|
23
|
+
RSpec.describe "Capybara::Session with Edge", capybara_skip: skipped_tests do
|
24
|
+
include Capybara::SpecHelper
|
25
|
+
include_examples "Capybara::Session", TestSessions::SeleniumEdge, :selenium_edge
|
26
|
+
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumEdge, :selenium_edge
|
27
|
+
end
|