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,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#reset_session!' do
|
2
3
|
it "removes cookies" do
|
3
4
|
@session.visit('/set_cookie')
|
@@ -32,12 +33,27 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
32
33
|
end
|
33
34
|
|
34
35
|
it "is synchronous" do
|
35
|
-
@session.visit("/
|
36
|
+
@session.visit("/with_slow_unload")
|
37
|
+
expect(@session).to have_selector(:css, 'div')
|
36
38
|
@session.reset_session!
|
37
39
|
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
|
38
40
|
end
|
39
41
|
|
40
|
-
it "
|
42
|
+
it "handles modals during unload", requires: [:modals] do
|
43
|
+
@session.visit('/with_unload_alert')
|
44
|
+
expect(@session).to have_selector(:css, 'div')
|
45
|
+
expect { @session.reset_session! }.not_to raise_error
|
46
|
+
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "handles already open modals", requires: [:modals] do
|
50
|
+
@session.visit('/with_unload_alert')
|
51
|
+
@session.click_link('Go away')
|
52
|
+
expect { @session.reset_session! }.not_to raise_error
|
53
|
+
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises any standard errors caught inside the server", requires: [:server] do
|
41
57
|
quietly { @session.visit("/error") }
|
42
58
|
expect do
|
43
59
|
@session.reset_session!
|
@@ -46,8 +62,33 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
46
62
|
expect(@session.current_path).to eq("/")
|
47
63
|
end
|
48
64
|
|
49
|
-
|
50
|
-
|
65
|
+
context "When reuse_server == false" do
|
66
|
+
before do
|
67
|
+
@reuse_server = Capybara.reuse_server
|
68
|
+
Capybara.reuse_server = false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "raises any standard errors caught inside the server during a second session", requires: [:server] do
|
72
|
+
Capybara.using_driver(@session.mode) do
|
73
|
+
Capybara.using_session(:another_session) do
|
74
|
+
@another_session = Capybara.current_session
|
75
|
+
quietly { @another_session.visit("/error") }
|
76
|
+
expect do
|
77
|
+
@another_session.reset_session!
|
78
|
+
end.to raise_error(TestApp::TestAppError)
|
79
|
+
@another_session.visit("/")
|
80
|
+
expect(@another_session.current_path).to eq("/")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
after do
|
86
|
+
Capybara.reuse_server = @reuse_server
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "raises configured errors caught inside the server", requires: [:server] do
|
91
|
+
prev_errors = Capybara.server_errors.dup
|
51
92
|
|
52
93
|
Capybara.server_errors = [LoadError]
|
53
94
|
quietly { @session.visit("/error") }
|
@@ -63,7 +104,7 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
63
104
|
Capybara.server_errors = prev_errors
|
64
105
|
end
|
65
106
|
|
66
|
-
it "ignores server errors when `Capybara.raise_server_errors = false`", :
|
107
|
+
it "ignores server errors when `Capybara.raise_server_errors = false`", requires: [:server] do
|
67
108
|
Capybara.raise_server_errors = false
|
68
109
|
quietly { @session.visit("/error") }
|
69
110
|
@session.reset_session!
|
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#status_code' do
|
2
|
-
it "should return response codes", :
|
3
|
+
it "should return response codes", requires: [:status_code] do
|
3
4
|
@session.visit('/with_simple_html')
|
4
5
|
expect(@session.status_code).to eq(200)
|
5
6
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'launchy'
|
2
3
|
|
3
4
|
Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
@@ -5,7 +6,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
5
6
|
@session.visit '/'
|
6
7
|
end
|
7
8
|
|
8
|
-
it 'opens file from the default directory', :
|
9
|
+
it 'opens file from the default directory', requires: [:screenshot] do
|
9
10
|
expected_file_regex = %r{capybara-\d+\.png}
|
10
11
|
allow(@session.driver).to receive(:save_screenshot)
|
11
12
|
allow(Launchy).to receive(:open)
|
@@ -17,7 +18,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
17
18
|
expect(Launchy).to have_received(:open).with(expected_file_regex)
|
18
19
|
end
|
19
20
|
|
20
|
-
it 'opens file from the provided directory', :
|
21
|
+
it 'opens file from the provided directory', requires: [:screenshot] do
|
21
22
|
custom_path = 'screenshots/1.png'
|
22
23
|
allow(@session.driver).to receive(:save_screenshot)
|
23
24
|
allow(Launchy).to receive(:open)
|
@@ -25,12 +26,12 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
25
26
|
@session.save_and_open_screenshot(custom_path)
|
26
27
|
|
27
28
|
expect(@session.driver).to have_received(:save_screenshot).
|
28
|
-
with(custom_path
|
29
|
-
expect(Launchy).to have_received(:open).with(custom_path)
|
29
|
+
with(/#{custom_path}$/, {})
|
30
|
+
expect(Launchy).to have_received(:open).with(/#{custom_path}$/)
|
30
31
|
end
|
31
32
|
|
32
33
|
context 'when launchy cannot be required' do
|
33
|
-
it 'prints out a correct warning message', :
|
34
|
+
it 'prints out a correct warning message', requires: [:screenshot] do
|
34
35
|
file_path = File.join(Dir.tmpdir, 'test.png')
|
35
36
|
allow(@session).to receive(:require).with('launchy').and_raise(LoadError)
|
36
37
|
allow(@session).to receive(:warn)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#save_page' do
|
2
3
|
let(:alternative_path) { File.join(Dir.pwd, "save_and_open_page_tmp") }
|
3
4
|
before do
|
@@ -6,6 +7,7 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
6
7
|
|
7
8
|
after do
|
8
9
|
Capybara.save_and_open_page_path = nil
|
10
|
+
Capybara.save_path = nil
|
9
11
|
Dir.glob("capybara-*.html").each do |file|
|
10
12
|
FileUtils.rm(file)
|
11
13
|
end
|
@@ -25,7 +27,7 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
it "can store files in a specified directory" do
|
28
|
-
Capybara.
|
30
|
+
Capybara.save_path = alternative_path
|
29
31
|
@session.save_page
|
30
32
|
path = Dir.glob(alternative_path + "/capybara-*.html").first
|
31
33
|
expect(File.read(path)).to include("Another World")
|
@@ -36,6 +38,20 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
36
38
|
expect(File.read("capybara-001122.html")).to include("Another World")
|
37
39
|
end
|
38
40
|
|
41
|
+
it "can store files in a specified directory with a given filename" do
|
42
|
+
Capybara.save_path = alternative_path
|
43
|
+
@session.save_page("capybara-001133.html")
|
44
|
+
path = alternative_path + "/capybara-001133.html"
|
45
|
+
expect(File.read(path)).to include("Another World")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can store files in a specified directory with a given relative filename" do
|
49
|
+
Capybara.save_path = alternative_path
|
50
|
+
@session.save_page("tmp/capybara-001144.html")
|
51
|
+
path = alternative_path + "/tmp/capybara-001144.html"
|
52
|
+
expect(File.read(path)).to include("Another World")
|
53
|
+
end
|
54
|
+
|
39
55
|
it "returns an absolute path in pwd" do
|
40
56
|
result = @session.save_page
|
41
57
|
path = File.expand_path(Dir.glob("capybara-*.html").first, Dir.pwd)
|
@@ -43,7 +59,7 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
43
59
|
end
|
44
60
|
|
45
61
|
it "returns an absolute path in given directory" do
|
46
|
-
Capybara.
|
62
|
+
Capybara.save_path = alternative_path
|
47
63
|
result = @session.save_page
|
48
64
|
path = File.expand_path(Dir.glob(alternative_path + "/capybara-*.html").first, alternative_path)
|
49
65
|
expect(result).to eq(path)
|
@@ -88,4 +104,20 @@ Capybara::SpecHelper.spec '#save_page' do
|
|
88
104
|
expect(result).to include("Bar")
|
89
105
|
end
|
90
106
|
end
|
107
|
+
|
108
|
+
context "with deprecated save_and_open_page_path" do
|
109
|
+
it "can store files in a specified directory" do
|
110
|
+
Capybara.save_and_open_page_path = alternative_path
|
111
|
+
@session.save_page
|
112
|
+
path = Dir.glob(alternative_path + "/capybara-*.html").first
|
113
|
+
expect(File.read(path)).to include("Another World")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns an absolute path in given directory" do
|
117
|
+
Capybara.save_and_open_page_path = alternative_path
|
118
|
+
result = @session.save_page
|
119
|
+
path = File.expand_path(Dir.glob(alternative_path + "/capybara-*.html").first, alternative_path)
|
120
|
+
expect(result).to eq(path)
|
121
|
+
end
|
122
|
+
end
|
91
123
|
end
|
@@ -1,8 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
3
|
+
let(:alternative_path) { File.join(Dir.pwd, "save_screenshot_tmp") }
|
2
4
|
before do
|
3
5
|
@session.visit '/foo'
|
4
6
|
end
|
5
7
|
|
8
|
+
after do
|
9
|
+
Capybara.save_and_open_page_path = nil
|
10
|
+
Capybara.save_path = nil
|
11
|
+
FileUtils.rm_rf alternative_path
|
12
|
+
end
|
13
|
+
|
6
14
|
it "generates sensible filename" do
|
7
15
|
allow(@session.driver).to receive(:save_screenshot)
|
8
16
|
|
@@ -18,6 +26,28 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
|
|
18
26
|
custom_path = 'screenshots/1.png'
|
19
27
|
@session.save_screenshot(custom_path)
|
20
28
|
|
21
|
-
expect(@session.driver).to have_received(:save_screenshot).with(custom_path
|
29
|
+
expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/, {})
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with Capybara.save_path" do
|
33
|
+
it "file is generated in the correct location" do
|
34
|
+
Capybara.save_path = alternative_path
|
35
|
+
allow(@session.driver).to receive(:save_screenshot)
|
36
|
+
|
37
|
+
@session.save_screenshot
|
38
|
+
|
39
|
+
regexp = Regexp.new(File.expand_path('capybara-\d+\.png', alternative_path))
|
40
|
+
expect(@session.driver).to have_received(:save_screenshot).with(regexp, {})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "relative paths are relative to save_path" do
|
44
|
+
Capybara.save_path = alternative_path
|
45
|
+
allow(@session.driver).to receive(:save_screenshot)
|
46
|
+
|
47
|
+
custom_path = 'screenshots/2.png'
|
48
|
+
@session.save_screenshot(custom_path)
|
49
|
+
|
50
|
+
expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path), {})
|
51
|
+
end
|
22
52
|
end
|
23
53
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#coding: US-ASCII
|
1
|
+
# coding: US-ASCII
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
Capybara::SpecHelper.spec "#save_screenshot" do
|
3
5
|
let(:image_path) { File.join(Dir.tmpdir, 'capybara-screenshot.png') }
|
4
6
|
|
@@ -6,7 +8,7 @@ Capybara::SpecHelper.spec "#save_screenshot" do
|
|
6
8
|
@session.visit '/'
|
7
9
|
end
|
8
10
|
|
9
|
-
it "should generate PNG file", :
|
11
|
+
it "should generate PNG file", requires: [:screenshot] do
|
10
12
|
path = @session.save_screenshot image_path
|
11
13
|
|
12
14
|
magic = File.read(image_path, 4)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec "#select" do
|
2
3
|
before do
|
3
4
|
@session.visit('/form')
|
@@ -8,30 +9,31 @@ Capybara::SpecHelper.spec "#select" do
|
|
8
9
|
end
|
9
10
|
|
10
11
|
it "should return value of the selected option" do
|
11
|
-
@session.select("Miss", :
|
12
|
+
@session.select("Miss", from: 'Title')
|
12
13
|
expect(@session.find_field('Title').value).to eq('Miss')
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should allow selecting options where there are inexact matches" do
|
16
|
-
@session.select("Mr", :
|
17
|
+
@session.select("Mr", from: 'Title')
|
17
18
|
expect(@session.find_field('Title').value).to eq('Mr')
|
18
19
|
end
|
19
20
|
|
20
21
|
it "should allow selecting options where they are the only inexact match" do
|
21
|
-
@session.select("Mis", :
|
22
|
+
@session.select("Mis", from: 'Title')
|
22
23
|
expect(@session.find_field('Title').value).to eq('Miss')
|
23
24
|
end
|
24
25
|
|
25
26
|
it "should not allow selecting options where they are the only inexact match if `Capybara.exact_options = true`" do
|
27
|
+
expect_any_instance_of(Kernel).to receive(:warn).with(/^DEPRECATED:/)
|
26
28
|
Capybara.exact_options = true
|
27
29
|
expect do
|
28
|
-
@session.select("Mis", :
|
30
|
+
@session.select("Mis", from: 'Title')
|
29
31
|
end.to raise_error(Capybara::ElementNotFound)
|
30
32
|
end
|
31
33
|
|
32
34
|
it "should not allow selecting an option if the match is ambiguous" do
|
33
35
|
expect do
|
34
|
-
@session.select("M", :
|
36
|
+
@session.select("M", from: 'Title')
|
35
37
|
end.to raise_error(Capybara::Ambiguous)
|
36
38
|
end
|
37
39
|
|
@@ -40,13 +42,13 @@ Capybara::SpecHelper.spec "#select" do
|
|
40
42
|
end
|
41
43
|
|
42
44
|
it "should select an option from a select box by id" do
|
43
|
-
@session.select("Finish", :
|
45
|
+
@session.select("Finish", from: 'form_locale')
|
44
46
|
@session.click_button('awesome')
|
45
47
|
expect(extract_results(@session)['locale']).to eq('fi')
|
46
48
|
end
|
47
49
|
|
48
50
|
it "should select an option from a select box by label" do
|
49
|
-
@session.select("Finish", :
|
51
|
+
@session.select("Finish", from: 'Locale')
|
50
52
|
@session.click_button('awesome')
|
51
53
|
expect(extract_results(@session)['locale']).to eq('fi')
|
52
54
|
end
|
@@ -58,13 +60,13 @@ Capybara::SpecHelper.spec "#select" do
|
|
58
60
|
end
|
59
61
|
|
60
62
|
it "should escape quotes" do
|
61
|
-
@session.select("John's made-up language", :
|
63
|
+
@session.select("John's made-up language", from: 'Locale')
|
62
64
|
@session.click_button('awesome')
|
63
65
|
expect(extract_results(@session)['locale']).to eq('jo')
|
64
66
|
end
|
65
67
|
|
66
68
|
it "should obey from" do
|
67
|
-
@session.select("Miss", :
|
69
|
+
@session.select("Miss", from: "Other title")
|
68
70
|
@session.click_button('awesome')
|
69
71
|
results = extract_results(@session)
|
70
72
|
expect(results['other_title']).to eq("Miss")
|
@@ -72,30 +74,30 @@ Capybara::SpecHelper.spec "#select" do
|
|
72
74
|
end
|
73
75
|
|
74
76
|
it "show match labels with preceding or trailing whitespace" do
|
75
|
-
@session.select("Lojban", :
|
77
|
+
@session.select("Lojban", from: 'Locale')
|
76
78
|
@session.click_button('awesome')
|
77
79
|
expect(extract_results(@session)['locale']).to eq('jbo')
|
78
80
|
end
|
79
81
|
|
80
82
|
it "casts to string" do
|
81
|
-
@session.select(:"Miss", :
|
83
|
+
@session.select(:"Miss", from: :'Title')
|
82
84
|
expect(@session.find_field('Title').value).to eq('Miss')
|
83
85
|
end
|
84
86
|
|
85
87
|
context "with a locator that doesn't exist" do
|
86
88
|
it "should raise an error" do
|
87
|
-
msg = "Unable to find select box \"does not exist\""
|
89
|
+
msg = "Unable to find visible select box \"does not exist\" that is not disabled"
|
88
90
|
expect do
|
89
|
-
@session.select('foo', :
|
91
|
+
@session.select('foo', from: 'does not exist')
|
90
92
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
94
96
|
context "with an option that doesn't exist" do
|
95
97
|
it "should raise an error" do
|
96
|
-
msg =
|
98
|
+
msg = /^Unable to find visible option "Does not Exist" within/
|
97
99
|
expect do
|
98
|
-
@session.select('Does not Exist', :
|
100
|
+
@session.select('Does not Exist', from: 'form_locale')
|
99
101
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
100
102
|
end
|
101
103
|
end
|
@@ -103,20 +105,20 @@ Capybara::SpecHelper.spec "#select" do
|
|
103
105
|
context "on a disabled select" do
|
104
106
|
it "should raise an error" do
|
105
107
|
expect do
|
106
|
-
@session.select('Should not see me', :
|
108
|
+
@session.select('Should not see me', from: 'Disabled Select')
|
107
109
|
end.to raise_error(Capybara::ElementNotFound)
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
113
|
context "on a disabled option" do
|
112
114
|
it "should not select" do
|
113
|
-
@session.select('Other', :
|
115
|
+
@session.select('Other', from: 'form_title')
|
114
116
|
expect(@session.find_field('form_title').value).not_to eq 'Other'
|
115
117
|
end
|
116
118
|
|
117
119
|
it "should warn" do
|
118
120
|
expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once
|
119
|
-
@session.select('Other', :
|
121
|
+
@session.select('Other', from: 'form_title')
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
@@ -126,28 +128,28 @@ Capybara::SpecHelper.spec "#select" do
|
|
126
128
|
end
|
127
129
|
|
128
130
|
it "should return value of the selected options" do
|
129
|
-
@session.select("Ruby", :
|
130
|
-
@session.select("Javascript", :
|
131
|
+
@session.select("Ruby", from: 'Language')
|
132
|
+
@session.select("Javascript", from: 'Language')
|
131
133
|
expect(@session.find_field('Language').value).to include('Ruby', 'Javascript')
|
132
134
|
end
|
133
135
|
|
134
136
|
it "should select one option" do
|
135
|
-
@session.select("Ruby", :
|
137
|
+
@session.select("Ruby", from: 'Language')
|
136
138
|
@session.click_button('awesome')
|
137
139
|
expect(extract_results(@session)['languages']).to eq(['Ruby'])
|
138
140
|
end
|
139
141
|
|
140
142
|
it "should select multiple options" do
|
141
|
-
@session.select("Ruby", :
|
142
|
-
@session.select("Javascript", :
|
143
|
+
@session.select("Ruby", from: 'Language')
|
144
|
+
@session.select("Javascript", from: 'Language')
|
143
145
|
@session.click_button('awesome')
|
144
146
|
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
145
147
|
end
|
146
148
|
|
147
149
|
it "should remain selected if already selected" do
|
148
|
-
@session.select("Ruby", :
|
149
|
-
@session.select("Javascript", :
|
150
|
-
@session.select("Ruby", :
|
150
|
+
@session.select("Ruby", from: 'Language')
|
151
|
+
@session.select("Javascript", from: 'Language')
|
152
|
+
@session.select("Ruby", from: 'Language')
|
151
153
|
@session.click_button('awesome')
|
152
154
|
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
153
155
|
end
|
@@ -160,19 +162,19 @@ Capybara::SpecHelper.spec "#select" do
|
|
160
162
|
context "with :exact option" do
|
161
163
|
context "when `false`" do
|
162
164
|
it "can match select box approximately" do
|
163
|
-
@session.select("Finish", :
|
165
|
+
@session.select("Finish", from: "Loc", exact: false)
|
164
166
|
@session.click_button("awesome")
|
165
167
|
expect(extract_results(@session)["locale"]).to eq("fi")
|
166
168
|
end
|
167
169
|
|
168
170
|
it "can match option approximately" do
|
169
|
-
@session.select("Fin", :
|
171
|
+
@session.select("Fin", from: "Locale", exact: false)
|
170
172
|
@session.click_button("awesome")
|
171
173
|
expect(extract_results(@session)["locale"]).to eq("fi")
|
172
174
|
end
|
173
175
|
|
174
176
|
it "can match option approximately when :from not given" do
|
175
|
-
@session.select("made-up language", :
|
177
|
+
@session.select("made-up language", exact: false)
|
176
178
|
@session.click_button("awesome")
|
177
179
|
expect(extract_results(@session)["locale"]).to eq("jo")
|
178
180
|
end
|
@@ -181,19 +183,19 @@ Capybara::SpecHelper.spec "#select" do
|
|
181
183
|
context "when `true`" do
|
182
184
|
it "can match select box approximately" do
|
183
185
|
expect do
|
184
|
-
@session.select("Finish", :
|
186
|
+
@session.select("Finish", from: "Loc", exact: true)
|
185
187
|
end.to raise_error(Capybara::ElementNotFound)
|
186
188
|
end
|
187
189
|
|
188
190
|
it "can match option approximately" do
|
189
191
|
expect do
|
190
|
-
@session.select("Fin", :
|
192
|
+
@session.select("Fin", from: "Locale", exact: true)
|
191
193
|
end.to raise_error(Capybara::ElementNotFound)
|
192
194
|
end
|
193
195
|
|
194
196
|
it "can match option approximately when :from not given" do
|
195
197
|
expect do
|
196
|
-
@session.select("made-up language", :
|
198
|
+
@session.select("made-up language", exact: true)
|
197
199
|
end.to raise_error(Capybara::ElementNotFound)
|
198
200
|
end
|
199
201
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
Capybara::SpecHelper.spec Capybara::Selector do
|
2
|
+
before do
|
3
|
+
@session.visit('/form')
|
4
|
+
end
|
5
|
+
|
6
|
+
describe ":label selector" do
|
7
|
+
it "finds a label by text" do
|
8
|
+
expect(@session.find(:label, 'Customer Name').text).to eq 'Customer Name'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "finds a label by for attribute string" do
|
12
|
+
expect(@session.find(:label, for: 'form_other_title')['for']).to eq 'form_other_title'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "finds a label from nested input using :for filter with id string" do
|
16
|
+
expect(@session.find(:label, for: 'nested_label').text).to eq 'Nested Label'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "finds a label from nested input using :for filter with element" do
|
20
|
+
input = @session.find(:id, 'nested_label')
|
21
|
+
expect(@session.find(:label, for: input).text).to eq 'Nested Label'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "finds the label for an non-nested element when using :for filter" do
|
25
|
+
select = @session.find(:id, 'form_other_title')
|
26
|
+
expect(@session.find(:label, for: select)['for']).to eq 'form_other_title'
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with exact option" do
|
30
|
+
it "matches substrings" do
|
31
|
+
expect(@session.find(:label, 'Customer Na', exact: false).text).to eq 'Customer Name'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "doesn't match substrings" do
|
35
|
+
expect { @session.find(:label, 'Customer Na', exact: true) }.to raise_error(Capybara::ElementNotFound)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "field selectors" do
|
41
|
+
it "can find specifically by id" do
|
42
|
+
expect(@session.find(:field, id: 'customer_email').value).to eq "ben@ben.com"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can find specifically by name" do
|
46
|
+
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq "form_other_title"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can find specifically by placeholder" do
|
50
|
+
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq "form_first_name"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can find by type" do
|
54
|
+
expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
|
55
|
+
expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
|
56
|
+
expect(@session.find(:field, 'Confusion', type: 'textarea')['id']).to eq 'confusion_textarea'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can find by class" do
|
60
|
+
expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
|
61
|
+
expect(@session).to have_selector(:field, class: 'confusion', count: 3)
|
62
|
+
expect(@session.find(:field, class: ['confusion','confusion-textarea'])['id']).to eq 'confusion_textarea'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Capybara::SpecHelper.spec '#sibling' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
after do
|
8
|
+
Capybara::Selector.remove(:monkey)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should find a prior sibling element using the given locator" do
|
12
|
+
el = @session.find(:css, '#mid_sibling')
|
13
|
+
expect(el.sibling('//div[@data-pre]')[:id]).to eq('pre_sibling')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find a following sibling element using the given locator" do
|
17
|
+
el = @session.find(:css, '#mid_sibling')
|
18
|
+
expect(el.sibling('//div[@data-post]')[:id]).to eq('post_sibling')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise an error if there are multiple matches" do
|
22
|
+
el = @session.find(:css, '#mid_sibling')
|
23
|
+
expect { el.sibling('//div') }.to raise_error(Capybara::Ambiguous)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with css selectors" do
|
27
|
+
it "should find the first element using the given locator" do
|
28
|
+
el = @session.find(:css, '#mid_sibling')
|
29
|
+
expect(el.sibling(:css, '#pre_sibling')).to have_text('Pre Sibling')
|
30
|
+
expect(el.sibling(:css, '#post_sibling')).to have_text('Post Sibling')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with custom selector" do
|
35
|
+
it "should use the custom selector" do
|
36
|
+
Capybara.add_selector(:data_attribute) do
|
37
|
+
xpath { |attr| ".//*[@data-#{attr}]" }
|
38
|
+
end
|
39
|
+
el = @session.find(:css, '#mid_sibling')
|
40
|
+
expect(el.sibling(:data_attribute, 'pre').text).to eq('Pre Sibling')
|
41
|
+
expect(el.sibling(:data_attribute, 'post').text).to eq('Post Sibling')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "should raise ElementNotFound with a useful default message if nothing was found" do
|
47
|
+
el = @session.find(:css, '#child')
|
48
|
+
expect do
|
49
|
+
el.sibling(:xpath, '//div[@id="nosuchthing"]')
|
50
|
+
end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\" that is a sibling of visible css \"#child\"")
|
51
|
+
end
|
52
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
Capybara::SpecHelper.spec '#text' do
|
2
3
|
it "should print the text of the page" do
|
3
4
|
@session.visit('/with_simple_html')
|
@@ -34,7 +35,7 @@ Capybara::SpecHelper.spec '#text' do
|
|
34
35
|
Capybara.ignore_hidden_elements = false
|
35
36
|
expect(@session.find(:id, "hidden-text").text).to eq('Some of this text is')
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
it "ignores invisible text if ancestor is invisible" do
|
39
40
|
@session.visit('/with_html')
|
40
41
|
expect(@session.find(:id, "hidden_via_ancestor", visible: false).text).to eq('')
|
@@ -51,8 +52,7 @@ Capybara::SpecHelper.spec '#text' do
|
|
51
52
|
|
52
53
|
it "should strip whitespace" do
|
53
54
|
@session.visit('/with_html')
|
54
|
-
|
55
|
-
expect(@session.find(:css, '#second').text).to match
|
56
|
-
/\ADuis aute .* text with whitespace .* est laborum\.\z/
|
55
|
+
@session.find(:css, '#second')
|
56
|
+
expect(@session.find(:css, '#second').text).to match(/\ADuis aute .* text with whitespace .* est laborum\.\z/)
|
57
57
|
end
|
58
58
|
end
|