capybara 2.5.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
- data/.yard/templates_custom/default/class/html/setup.rb +17 -0
- data/.yard/yard_extensions.rb +78 -0
- data/.yardopts +1 -0
- data/History.md +413 -10
- data/License.txt +1 -1
- data/README.md +237 -130
- data/lib/capybara/config.rb +132 -0
- data/lib/capybara/cucumber.rb +3 -1
- data/lib/capybara/driver/base.rb +27 -6
- data/lib/capybara/driver/node.rb +14 -5
- data/lib/capybara/dsl.rb +2 -3
- data/lib/capybara/helpers.rb +13 -65
- data/lib/capybara/minitest/spec.rb +177 -0
- data/lib/capybara/minitest.rb +278 -0
- data/lib/capybara/node/actions.rb +180 -24
- data/lib/capybara/node/base.rb +17 -5
- data/lib/capybara/node/document.rb +5 -0
- data/lib/capybara/node/document_matchers.rb +15 -14
- data/lib/capybara/node/element.rb +55 -7
- data/lib/capybara/node/finders.rb +179 -67
- data/lib/capybara/node/matchers.rb +301 -105
- data/lib/capybara/node/simple.rb +15 -4
- data/lib/capybara/queries/ancestor_query.rb +25 -0
- data/lib/capybara/queries/base_query.rb +69 -3
- data/lib/capybara/queries/current_path_query.rb +17 -8
- data/lib/capybara/queries/match_query.rb +19 -0
- data/lib/capybara/queries/selector_query.rb +251 -0
- data/lib/capybara/queries/sibling_query.rb +25 -0
- data/lib/capybara/queries/text_query.rb +67 -16
- data/lib/capybara/queries/title_query.rb +4 -2
- data/lib/capybara/query.rb +3 -131
- data/lib/capybara/rack_test/browser.rb +14 -5
- data/lib/capybara/rack_test/css_handlers.rb +1 -0
- data/lib/capybara/rack_test/driver.rb +15 -8
- data/lib/capybara/rack_test/form.rb +34 -12
- data/lib/capybara/rack_test/node.rb +29 -12
- data/lib/capybara/rails.rb +3 -3
- data/lib/capybara/result.rb +104 -9
- data/lib/capybara/rspec/compound.rb +95 -0
- data/lib/capybara/rspec/features.rb +17 -6
- data/lib/capybara/rspec/matcher_proxies.rb +45 -0
- data/lib/capybara/rspec/matchers.rb +199 -80
- data/lib/capybara/rspec.rb +4 -2
- data/lib/capybara/selector/css.rb +30 -0
- data/lib/capybara/selector/filter.rb +20 -0
- data/lib/capybara/selector/filter_set.rb +74 -0
- data/lib/capybara/selector/filters/base.rb +33 -0
- data/lib/capybara/selector/filters/expression_filter.rb +40 -0
- data/lib/capybara/selector/filters/node_filter.rb +27 -0
- data/lib/capybara/selector/selector.rb +276 -0
- data/lib/capybara/selector.rb +452 -157
- data/lib/capybara/selenium/driver.rb +282 -81
- data/lib/capybara/selenium/node.rb +144 -46
- data/lib/capybara/server.rb +59 -16
- data/lib/capybara/session/config.rb +114 -0
- data/lib/capybara/session/matchers.rb +29 -19
- data/lib/capybara/session.rb +378 -143
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +13 -791
- data/lib/capybara/spec/public/jquery.js +4 -9045
- data/lib/capybara/spec/public/test.js +45 -11
- data/lib/capybara/spec/session/accept_alert_spec.rb +30 -7
- data/lib/capybara/spec/session/accept_confirm_spec.rb +14 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +35 -6
- data/lib/capybara/spec/session/all_spec.rb +45 -32
- data/lib/capybara/spec/session/ancestor_spec.rb +85 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +110 -0
- data/lib/capybara/spec/session/assert_current_path.rb +15 -2
- data/lib/capybara/spec/session/assert_selector.rb +29 -28
- data/lib/capybara/spec/session/assert_text.rb +59 -20
- data/lib/capybara/spec/session/assert_title.rb +25 -11
- data/lib/capybara/spec/session/attach_file_spec.rb +42 -4
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +90 -14
- data/lib/capybara/spec/session/choose_spec.rb +31 -5
- data/lib/capybara/spec/session/click_button_spec.rb +20 -9
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +15 -9
- data/lib/capybara/spec/session/click_link_spec.rb +39 -15
- data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
- data/lib/capybara/spec/session/current_url_spec.rb +12 -3
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +6 -5
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +4 -3
- data/lib/capybara/spec/session/element/assert_match_selector.rb +36 -0
- data/lib/capybara/spec/session/element/match_css_spec.rb +23 -0
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +106 -0
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +22 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +23 -1
- data/lib/capybara/spec/session/execute_script_spec.rb +22 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +50 -32
- data/lib/capybara/spec/session/find_button_spec.rb +43 -2
- data/lib/capybara/spec/session/find_by_id_spec.rb +3 -2
- data/lib/capybara/spec/session/find_field_spec.rb +42 -6
- data/lib/capybara/spec/session/find_link_spec.rb +22 -3
- data/lib/capybara/spec/session/find_spec.rb +103 -57
- data/lib/capybara/spec/session/first_spec.rb +34 -18
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +103 -0
- data/lib/capybara/spec/session/{within_frame_spec.rb → frame/within_frame_spec.rb} +44 -2
- data/lib/capybara/spec/session/go_back_spec.rb +2 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_button_spec.rb +17 -8
- data/lib/capybara/spec/session/has_css_spec.rb +85 -73
- data/lib/capybara/spec/session/has_current_path_spec.rb +91 -7
- data/lib/capybara/spec/session/has_field_spec.rb +93 -58
- data/lib/capybara/spec/session/has_link_spec.rb +9 -8
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
- data/lib/capybara/spec/session/has_select_spec.rb +159 -59
- data/lib/capybara/spec/session/has_selector_spec.rb +64 -28
- data/lib/capybara/spec/session/has_table_spec.rb +1 -0
- data/lib/capybara/spec/session/has_text_spec.rb +27 -12
- data/lib/capybara/spec/session/has_title_spec.rb +22 -4
- data/lib/capybara/spec/session/has_xpath_spec.rb +32 -29
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +4 -3
- data/lib/capybara/spec/session/node_spec.rb +198 -38
- data/lib/capybara/spec/session/refresh_spec.rb +28 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +46 -5
- data/lib/capybara/spec/session/response_code.rb +2 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -5
- data/lib/capybara/spec/session/save_page_spec.rb +34 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
- data/lib/capybara/spec/session/screenshot_spec.rb +4 -2
- data/lib/capybara/spec/session/select_spec.rb +34 -32
- data/lib/capybara/spec/session/selectors_spec.rb +65 -0
- data/lib/capybara/spec/session/sibling_spec.rb +52 -0
- data/lib/capybara/spec/session/text_spec.rb +4 -4
- data/lib/capybara/spec/session/title_spec.rb +2 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +42 -2
- data/lib/capybara/spec/session/unselect_spec.rb +17 -16
- data/lib/capybara/spec/session/visit_spec.rb +77 -2
- data/lib/capybara/spec/session/window/become_closed_spec.rb +12 -11
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -11
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +7 -4
- data/lib/capybara/spec/session/window/window_spec.rb +36 -29
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
- data/lib/capybara/spec/session/window/within_window_spec.rb +31 -7
- data/lib/capybara/spec/session/within_spec.rb +14 -6
- data/lib/capybara/spec/spec_helper.rb +37 -4
- data/lib/capybara/spec/test_app.rb +15 -3
- data/lib/capybara/spec/views/buttons.erb +1 -0
- data/lib/capybara/spec/views/fieldsets.erb +2 -1
- data/lib/capybara/spec/views/form.erb +169 -9
- data/lib/capybara/spec/views/frame_child.erb +10 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +3 -2
- data/lib/capybara/spec/views/frame_two.erb +2 -1
- data/lib/capybara/spec/views/header_links.erb +1 -0
- data/lib/capybara/spec/views/host_links.erb +1 -0
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/path.erb +1 -0
- data/lib/capybara/spec/views/popup_one.erb +1 -0
- data/lib/capybara/spec/views/popup_two.erb +1 -0
- data/lib/capybara/spec/views/postback.erb +2 -1
- data/lib/capybara/spec/views/tables.erb +1 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -0
- data/lib/capybara/spec/views/with_count.erb +2 -1
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +7 -1
- data/lib/capybara/spec/views/with_html.erb +40 -2
- data/lib/capybara/spec/views/with_html_entities.erb +1 -0
- data/lib/capybara/spec/views/with_js.erb +32 -1
- data/lib/capybara/spec/views/with_scope.erb +1 -0
- data/lib/capybara/spec/views/with_simple_html.erb +2 -1
- data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
- data/lib/capybara/spec/views/with_title.erb +2 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +14 -0
- data/lib/capybara/spec/views/with_windows.erb +7 -0
- data/lib/capybara/spec/views/within_frames.erb +3 -2
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +20 -3
- data/lib/capybara.rb +189 -93
- data/spec/basic_node_spec.rb +7 -6
- data/spec/capybara_spec.rb +90 -4
- data/spec/dsl_spec.rb +3 -1
- data/spec/filter_set_spec.rb +28 -0
- data/spec/fixtures/capybara.csv +1 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +5 -1
- data/spec/minitest_spec.rb +130 -0
- data/spec/minitest_spec_spec.rb +135 -0
- data/spec/per_session_config_spec.rb +67 -0
- data/spec/rack_test_spec.rb +50 -7
- data/spec/result_spec.rb +76 -0
- data/spec/rspec/features_spec.rb +21 -8
- data/spec/rspec/scenarios_spec.rb +21 -0
- data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +160 -54
- data/spec/rspec/views_spec.rb +5 -0
- data/spec/rspec_matchers_spec.rb +46 -0
- data/spec/rspec_spec.rb +79 -1
- data/spec/selector_spec.rb +199 -0
- data/spec/selenium_spec_chrome.rb +54 -9
- data/spec/selenium_spec_firefox.rb +68 -0
- data/spec/selenium_spec_marionette.rb +127 -0
- data/spec/server_spec.rb +102 -14
- data/spec/session_spec.rb +54 -0
- data/spec/shared_selenium_session.rb +215 -0
- data/spec/spec_helper.rb +7 -0
- metadata +140 -15
- data/spec/selenium_spec.rb +0 -128
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
Capybara::SpecHelper.spec "#evaluate_async_script", requires: [:js] do
|
|
3
|
+
it "should evaluate the given script and return whatever it produces" do
|
|
4
|
+
@session.visit('/with_js')
|
|
5
|
+
expect(@session.evaluate_async_script("arguments[0](4)")).to eq(4)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
|
|
9
|
+
@session.visit('/with_js')
|
|
10
|
+
el = @session.find(:css, '#drag p')
|
|
11
|
+
result = @session.evaluate_async_script("arguments[2]([arguments[0].innerText, arguments[1]])", el, "Doodle Funk")
|
|
12
|
+
expect(result).to eq ["This is a draggable element.", "Doodle Funk"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should support returning elements after asynchronous operation", requires: [:js, :es_args] do
|
|
16
|
+
@session.visit('/with_js')
|
|
17
|
+
@session.find(:css, '#change') # ensure page has loaded and element is available
|
|
18
|
+
el = @session.evaluate_async_script("var cb = arguments[0]; setTimeout(function(){ cb(document.getElementById('change')) }, 100)")
|
|
19
|
+
expect(el).to be_instance_of(Capybara::Node::Element)
|
|
20
|
+
expect(el).to eq(@session.find(:css, '#change'))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
Capybara::SpecHelper.spec "#evaluate_script", requires: [:js] do
|
|
2
3
|
it "should evaluate the given script and return whatever it produces" do
|
|
3
4
|
@session.visit('/with_js')
|
|
4
5
|
expect(@session.evaluate_script("1+3")).to eq(4)
|
|
5
6
|
end
|
|
7
|
+
|
|
8
|
+
it "should pass arguments to the script", requires: [:js, :es_args] do
|
|
9
|
+
@session.visit('/with_js')
|
|
10
|
+
@session.evaluate_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
|
|
11
|
+
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
|
|
15
|
+
@session.visit('/with_js')
|
|
16
|
+
el = @session.find(:css, '#change')
|
|
17
|
+
@session.evaluate_script("arguments[0].textContent = arguments[1]", el, "Doodle Funk")
|
|
18
|
+
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should support returning elements", requires: [:js, :es_args] do
|
|
22
|
+
@session.visit('/with_js')
|
|
23
|
+
@session.find(:css, '#change') # ensure page has loaded and element is available
|
|
24
|
+
el = @session.evaluate_script("document.getElementById('change')")
|
|
25
|
+
expect(el).to be_instance_of(Capybara::Node::Element)
|
|
26
|
+
expect(el).to eq(@session.find(:css, '#change'))
|
|
27
|
+
end
|
|
6
28
|
end
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
|
|
2
3
|
it "should execute the given script and return nothing" do
|
|
3
4
|
@session.visit('/with_js')
|
|
4
|
-
expect(@session.execute_script("
|
|
5
|
-
expect(@session).to have_css('#change', :
|
|
5
|
+
expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
|
|
6
|
+
expect(@session).to have_css('#change', text: 'Funky Doodle')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should be able to call functions defined in the page" do
|
|
10
|
+
@session.visit('/with_js')
|
|
11
|
+
expect{ @session.execute_script("$('#change').text('Funky Doodle')") }.not_to raise_error
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should pass arguments to the script", requires: [:js, :es_args] do
|
|
15
|
+
@session.visit('/with_js')
|
|
16
|
+
@session.execute_script("document.getElementById('change').textContent = arguments[0]", "Doodle Funk")
|
|
17
|
+
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should support passing elements as arguments to the script", requires: [:js, :es_args] do
|
|
21
|
+
@session.visit('/with_js')
|
|
22
|
+
el = @session.find(:css, '#change')
|
|
23
|
+
@session.execute_script("arguments[1].textContent = arguments[0]", "Doodle Funk", el)
|
|
24
|
+
expect(@session).to have_css('#change', text: 'Doodle Funk')
|
|
6
25
|
end
|
|
7
26
|
end
|
|
@@ -1,141 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Capybara::SpecHelper.spec "#fill_in" do
|
|
2
3
|
before do
|
|
3
4
|
@session.visit('/form')
|
|
4
5
|
end
|
|
5
6
|
|
|
6
7
|
it "should fill in a text field by id" do
|
|
7
|
-
@session.fill_in('form_first_name', :
|
|
8
|
+
@session.fill_in('form_first_name', with: 'Harry')
|
|
8
9
|
@session.click_button('awesome')
|
|
9
10
|
expect(extract_results(@session)['first_name']).to eq('Harry')
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
it "should fill in a text field by name" do
|
|
13
|
-
@session.fill_in('form[last_name]', :
|
|
14
|
+
@session.fill_in('form[last_name]', with: 'Green')
|
|
14
15
|
@session.click_button('awesome')
|
|
15
16
|
expect(extract_results(@session)['last_name']).to eq('Green')
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
it "should fill in a text field by label without for" do
|
|
19
|
-
@session.fill_in('First Name', :
|
|
20
|
+
@session.fill_in('First Name', with: 'Harry')
|
|
20
21
|
@session.click_button('awesome')
|
|
21
22
|
expect(extract_results(@session)['first_name']).to eq('Harry')
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
it "should fill in a url field by label without for" do
|
|
25
|
-
@session.fill_in('Html5 Url', :
|
|
26
|
+
@session.fill_in('Html5 Url', with: 'http://www.avenueq.com')
|
|
26
27
|
@session.click_button('html5_submit')
|
|
27
28
|
expect(extract_results(@session)['html5_url']).to eq('http://www.avenueq.com')
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
it "should fill in a textarea by id" do
|
|
31
|
-
@session.fill_in('form_description', :
|
|
32
|
+
@session.fill_in('form_description', with: 'Texty text')
|
|
32
33
|
@session.click_button('awesome')
|
|
33
34
|
expect(extract_results(@session)['description']).to eq('Texty text')
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
it "should fill in a textarea by label" do
|
|
37
|
-
@session.fill_in('Description', :
|
|
38
|
+
@session.fill_in('Description', with: 'Texty text')
|
|
38
39
|
@session.click_button('awesome')
|
|
39
40
|
expect(extract_results(@session)['description']).to eq('Texty text')
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
it "should fill in a textarea by name" do
|
|
43
|
-
@session.fill_in('form[description]', :
|
|
44
|
+
@session.fill_in('form[description]', with: 'Texty text')
|
|
44
45
|
@session.click_button('awesome')
|
|
45
46
|
expect(extract_results(@session)['description']).to eq('Texty text')
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
it "should fill in a password field by id" do
|
|
49
|
-
@session.fill_in('form_password', :
|
|
50
|
+
@session.fill_in('form_password', with: 'supasikrit')
|
|
50
51
|
@session.click_button('awesome')
|
|
51
52
|
expect(extract_results(@session)['password']).to eq('supasikrit')
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
it "should handle HTML in a textarea" do
|
|
55
|
-
@session.fill_in('form_description', :
|
|
56
|
+
@session.fill_in('form_description', with: 'is <strong>very</strong> secret!')
|
|
56
57
|
@session.click_button('awesome')
|
|
57
58
|
expect(extract_results(@session)['description']).to eq('is <strong>very</strong> secret!')
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
it "should handle newlines in a textarea" do
|
|
61
|
-
@session.fill_in('form_description', :
|
|
62
|
+
@session.fill_in('form_description', with: "\nSome text\n")
|
|
62
63
|
@session.click_button('awesome')
|
|
63
64
|
expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n")
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
it "should fill in a field with a custom type" do
|
|
67
|
-
@session.fill_in('Schmooo', :
|
|
68
|
+
@session.fill_in('Schmooo', with: 'Schmooo is the game')
|
|
68
69
|
@session.click_button('awesome')
|
|
69
70
|
expect(extract_results(@session)['schmooo']).to eq('Schmooo is the game')
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
it "should fill in a field without a type" do
|
|
73
|
-
@session.fill_in('Phone', :
|
|
74
|
+
@session.fill_in('Phone', with: '+1 555 7022')
|
|
74
75
|
@session.click_button('awesome')
|
|
75
76
|
expect(extract_results(@session)['phone']).to eq('+1 555 7022')
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
it "should fill in a text field respecting its maxlength attribute" do
|
|
79
|
-
@session.fill_in('Zipcode', :
|
|
80
|
+
@session.fill_in('Zipcode', with: '52071350')
|
|
80
81
|
@session.click_button('awesome')
|
|
81
82
|
expect(extract_results(@session)['zipcode']).to eq('52071')
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
it "should fill in a password field by name" do
|
|
85
|
-
@session.fill_in('form[password]', :
|
|
86
|
+
@session.fill_in('form[password]', with: 'supasikrit')
|
|
86
87
|
@session.click_button('awesome')
|
|
87
88
|
expect(extract_results(@session)['password']).to eq('supasikrit')
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
it "should fill in a password field by label" do
|
|
91
|
-
@session.fill_in('Password', :
|
|
92
|
+
@session.fill_in('Password', with: 'supasikrit')
|
|
92
93
|
@session.click_button('awesome')
|
|
93
94
|
expect(extract_results(@session)['password']).to eq('supasikrit')
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
it "should fill in a password field by name" do
|
|
97
|
-
@session.fill_in('form[password]', :
|
|
98
|
+
@session.fill_in('form[password]', with: 'supasikrit')
|
|
98
99
|
@session.click_button('awesome')
|
|
99
100
|
expect(extract_results(@session)['password']).to eq('supasikrit')
|
|
100
101
|
end
|
|
101
102
|
|
|
103
|
+
it "should fill in a field based on current value" do
|
|
104
|
+
@session.fill_in(currently_with: 'John', with: 'Thomas')
|
|
105
|
+
@session.click_button('awesome')
|
|
106
|
+
expect(extract_results(@session)['first_name']).to eq('Thomas')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should fill in a field based on type" do
|
|
110
|
+
@session.fill_in(type: 'schmooo', with: 'Schmooo for all')
|
|
111
|
+
@session.click_button('awesome')
|
|
112
|
+
expect(extract_results(@session)['schmooo']).to eq('Schmooo for all')
|
|
113
|
+
end
|
|
114
|
+
|
|
102
115
|
it "should throw an exception if a hash containing 'with' is not provided" do
|
|
103
116
|
expect {@session.fill_in 'Name', 'ignu'}.to raise_error(RuntimeError, /with/)
|
|
104
117
|
end
|
|
105
118
|
|
|
106
|
-
it "should wait for asynchronous load", :
|
|
119
|
+
it "should wait for asynchronous load", requires: [:js] do
|
|
107
120
|
@session.visit('/with_js')
|
|
108
121
|
@session.click_link('Click me')
|
|
109
|
-
@session.fill_in('new_field', :
|
|
122
|
+
@session.fill_in('new_field', with: 'Testing...')
|
|
110
123
|
end
|
|
111
124
|
|
|
112
125
|
it "casts to string" do
|
|
113
|
-
@session.fill_in(:'form_first_name', :
|
|
126
|
+
@session.fill_in(:'form_first_name', with: :'Harry')
|
|
114
127
|
@session.click_button('awesome')
|
|
115
128
|
expect(extract_results(@session)['first_name']).to eq('Harry')
|
|
116
129
|
end
|
|
117
130
|
|
|
118
131
|
it "casts to string if field has maxlength" do
|
|
119
|
-
@session.fill_in(:'form_zipcode', :
|
|
132
|
+
@session.fill_in(:'form_zipcode', with: 1234567)
|
|
120
133
|
@session.click_button('awesome')
|
|
121
134
|
expect(extract_results(@session)['zipcode']).to eq('12345')
|
|
122
135
|
end
|
|
123
136
|
|
|
124
|
-
context 'on a pre-populated textfield with a reformatting onchange', :
|
|
137
|
+
context 'on a pre-populated textfield with a reformatting onchange', requires: [:js] do
|
|
125
138
|
it 'should only trigger onchange once' do
|
|
126
139
|
@session.visit('/with_js')
|
|
127
|
-
@session.fill_in('with_change_event', :
|
|
140
|
+
@session.fill_in('with_change_event', with: 'some value')
|
|
128
141
|
# click outside the field to trigger the change event
|
|
129
142
|
@session.find(:css, 'body').click
|
|
130
|
-
expect(@session.find(:css, '.change_event_triggered', :
|
|
143
|
+
expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
|
|
131
144
|
end
|
|
132
145
|
|
|
133
146
|
it 'should trigger change when clearing field' do
|
|
134
147
|
@session.visit('/with_js')
|
|
135
|
-
@session.fill_in('with_change_event', :
|
|
148
|
+
@session.fill_in('with_change_event', with: '')
|
|
136
149
|
# click outside the field to trigger the change event
|
|
137
150
|
@session.find(:css, 'body').click
|
|
138
|
-
expect(@session).to have_selector(:css, '.change_event_triggered', :
|
|
151
|
+
expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
|
|
139
152
|
end
|
|
140
153
|
end
|
|
141
154
|
|
|
@@ -143,18 +156,18 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|
|
143
156
|
before { Capybara.ignore_hidden_elements = true }
|
|
144
157
|
after { Capybara.ignore_hidden_elements = false }
|
|
145
158
|
it "should not find a hidden field" do
|
|
146
|
-
msg = "Unable to find field \"Super Secret\""
|
|
159
|
+
msg = "Unable to find visible field \"Super Secret\" that is not disabled"
|
|
147
160
|
expect do
|
|
148
|
-
@session.fill_in('Super Secret', :
|
|
161
|
+
@session.fill_in('Super Secret', with: '777')
|
|
149
162
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
150
163
|
end
|
|
151
164
|
end
|
|
152
165
|
|
|
153
166
|
context "with a locator that doesn't exist" do
|
|
154
167
|
it "should raise an error" do
|
|
155
|
-
msg = "Unable to find field \"does not exist\""
|
|
168
|
+
msg = "Unable to find visible field \"does not exist\" that is not disabled"
|
|
156
169
|
expect do
|
|
157
|
-
@session.fill_in('does not exist', :
|
|
170
|
+
@session.fill_in('does not exist', with: 'Blah blah')
|
|
158
171
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
159
172
|
end
|
|
160
173
|
end
|
|
@@ -162,22 +175,27 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|
|
162
175
|
context "on a disabled field" do
|
|
163
176
|
it "should raise an error" do
|
|
164
177
|
expect do
|
|
165
|
-
@session.fill_in('Disabled Text Field', :
|
|
178
|
+
@session.fill_in('Disabled Text Field', with: 'Blah blah')
|
|
166
179
|
end.to raise_error(Capybara::ElementNotFound)
|
|
167
180
|
end
|
|
168
181
|
end
|
|
169
182
|
|
|
170
183
|
context "with :exact option" do
|
|
171
184
|
it "should accept partial matches when false" do
|
|
172
|
-
@session.fill_in("Explanation", :
|
|
185
|
+
@session.fill_in("Explanation", with: "Dude", exact: false)
|
|
173
186
|
@session.click_button("awesome")
|
|
174
187
|
expect(extract_results(@session)["name_explanation"]).to eq("Dude")
|
|
175
188
|
end
|
|
176
189
|
|
|
177
190
|
it "should not accept partial matches when true" do
|
|
178
191
|
expect do
|
|
179
|
-
@session.fill_in("Explanation", :
|
|
192
|
+
@session.fill_in("Explanation", with: "Dude", exact: true)
|
|
180
193
|
end.to raise_error(Capybara::ElementNotFound)
|
|
181
194
|
end
|
|
182
195
|
end
|
|
196
|
+
|
|
197
|
+
it "should return the element filled in" do
|
|
198
|
+
el = @session.find(:fillable_field, 'form_first_name')
|
|
199
|
+
expect(@session.fill_in('form_first_name', with: 'Harry')).to eq el
|
|
200
|
+
end
|
|
183
201
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Capybara::SpecHelper.spec '#find_button' do
|
|
2
3
|
before do
|
|
3
4
|
@session.visit('/form')
|
|
@@ -8,6 +9,18 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
|
8
9
|
expect(@session.find_button('crap321').value).to eq("crappy")
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
context "aria_label attribute with Capybara.enable_aria_label" do
|
|
13
|
+
it "should find when true" do
|
|
14
|
+
Capybara.enable_aria_label = true
|
|
15
|
+
expect(@session.find_button('Mediocre Button')[:id]).to eq("mediocre")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should not find when false" do
|
|
19
|
+
Capybara.enable_aria_label = false
|
|
20
|
+
expect { @session.find_button('Mediocre Button') }.to raise_error(Capybara::ElementNotFound)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
11
24
|
it "casts to string" do
|
|
12
25
|
expect(@session.find_button(:'med')[:id]).to eq("mediocre")
|
|
13
26
|
end
|
|
@@ -20,13 +33,41 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
|
20
33
|
|
|
21
34
|
context "with :exact option" do
|
|
22
35
|
it "should accept partial matches when false" do
|
|
23
|
-
expect(@session.find_button('What an Awesome', :
|
|
36
|
+
expect(@session.find_button('What an Awesome', exact: false).value).to eq("awesome")
|
|
24
37
|
end
|
|
25
38
|
|
|
26
39
|
it "should not accept partial matches when true" do
|
|
27
40
|
expect do
|
|
28
|
-
@session.find_button('What an Awesome', :
|
|
41
|
+
@session.find_button('What an Awesome', exact: true)
|
|
29
42
|
end.to raise_error(Capybara::ElementNotFound)
|
|
30
43
|
end
|
|
31
44
|
end
|
|
45
|
+
|
|
46
|
+
context "with :disabled option" do
|
|
47
|
+
it "should find disabled buttons when true" do
|
|
48
|
+
expect(@session.find_button('Disabled button', disabled: true).value).to eq("Disabled button")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should not find disabled buttons when false" do
|
|
52
|
+
expect do
|
|
53
|
+
@session.find_button('Disabled button', disabled: false)
|
|
54
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should default to not finding disabled buttons" do
|
|
58
|
+
expect do
|
|
59
|
+
@session.find_button('Disabled button')
|
|
60
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should find disabled buttons when :all" do
|
|
64
|
+
expect(@session.find_button('Disabled button', disabled: :all).value).to eq("Disabled button")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context "without locator" do
|
|
69
|
+
it "should use options" do
|
|
70
|
+
expect(@session.find_button(disabled: true).value).to eq("Disabled button")
|
|
71
|
+
end
|
|
72
|
+
end
|
|
32
73
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Capybara::SpecHelper.spec '#find_by_id' do
|
|
2
3
|
before do
|
|
3
4
|
@session.visit('/with_html')
|
|
@@ -19,12 +20,12 @@ Capybara::SpecHelper.spec '#find_by_id' do
|
|
|
19
20
|
|
|
20
21
|
context "with :visible option" do
|
|
21
22
|
it "finds invisible elements when `false`" do
|
|
22
|
-
expect(@session.find_by_id("hidden_via_ancestor", :
|
|
23
|
+
expect(@session.find_by_id("hidden_via_ancestor", visible: false).text(:all)).to match(/with hidden ancestor/)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
it "finds invisible elements when `false`" do
|
|
26
27
|
expect do
|
|
27
|
-
@session.find_by_id("hidden_via_ancestor", :
|
|
28
|
+
@session.find_by_id("hidden_via_ancestor", visible: true)
|
|
28
29
|
end.to raise_error(Capybara::ElementNotFound)
|
|
29
30
|
end
|
|
30
31
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Capybara::SpecHelper.spec '#find_field' do
|
|
2
3
|
before do
|
|
3
4
|
@session.visit('/form')
|
|
@@ -7,6 +8,21 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
|
7
8
|
expect(@session.find_field('Dog').value).to eq('dog')
|
|
8
9
|
expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
|
|
9
10
|
expect(@session.find_field('Region')[:name]).to eq('form[region]')
|
|
11
|
+
expect(@session.find_field('With Asterisk*')).to be
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "aria_label attribute with Capybara.enable_aria_label" do
|
|
15
|
+
it "should find when true" do
|
|
16
|
+
Capybara.enable_aria_label = true
|
|
17
|
+
expect(@session.find_field('Unlabelled Input')[:name]).to eq('form[which_form]')
|
|
18
|
+
# expect(@session.find_field('Emergency Number')[:id]).to eq('html5_tel')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should not find when false" do
|
|
22
|
+
Capybara.enable_aria_label = false
|
|
23
|
+
expect { @session.find_field('Unlabelled Input') }.to raise_error(Capybara::ElementNotFound)
|
|
24
|
+
# expect { @session.find_field('Emergency Number') }.to raise_error(Capybara::ElementNotFound)
|
|
25
|
+
end
|
|
10
26
|
end
|
|
11
27
|
|
|
12
28
|
it "casts to string" do
|
|
@@ -21,7 +37,7 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
|
21
37
|
|
|
22
38
|
it "should warn if filter option is invalid" do
|
|
23
39
|
expect_any_instance_of(Kernel).to receive(:warn).
|
|
24
|
-
with('Invalid value nil passed to filter disabled')
|
|
40
|
+
with('Invalid value nil passed to filter disabled - defaulting to false')
|
|
25
41
|
@session.find_field('Dog', disabled: nil)
|
|
26
42
|
end
|
|
27
43
|
|
|
@@ -34,24 +50,26 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
|
34
50
|
|
|
35
51
|
context "with :exact option" do
|
|
36
52
|
it "should accept partial matches when false" do
|
|
37
|
-
expect(@session.find_field("Explanation", :
|
|
53
|
+
expect(@session.find_field("Explanation", exact: false)[:name]).to eq("form[name_explanation]")
|
|
38
54
|
end
|
|
39
55
|
|
|
40
56
|
it "should not accept partial matches when true" do
|
|
41
57
|
expect do
|
|
42
|
-
@session.find_field("Explanation", :
|
|
58
|
+
@session.find_field("Explanation", exact: true)
|
|
43
59
|
end.to raise_error(Capybara::ElementNotFound)
|
|
44
60
|
end
|
|
45
61
|
end
|
|
46
62
|
|
|
47
63
|
context "with :disabled option" do
|
|
48
64
|
it "should find disabled fields when true" do
|
|
49
|
-
expect(@session.find_field("Disabled Checkbox", :
|
|
65
|
+
expect(@session.find_field("Disabled Checkbox", disabled: true)[:name]).to eq("form[disabled_checkbox]")
|
|
66
|
+
expect(@session.find_field("form_disabled_fieldset_child", disabled: true)[:name]).to eq("form[disabled_fieldset_child]")
|
|
67
|
+
expect(@session.find_field("form_disabled_fieldset_descendant", disabled: true)[:name]).to eq("form[disabled_fieldset_descendant]")
|
|
50
68
|
end
|
|
51
69
|
|
|
52
70
|
it "should not find disabled fields when false" do
|
|
53
71
|
expect do
|
|
54
|
-
@session.find_field("Disabled Checkbox", :
|
|
72
|
+
@session.find_field("Disabled Checkbox", disabled: false)
|
|
55
73
|
end.to raise_error(Capybara::ElementNotFound)
|
|
56
74
|
end
|
|
57
75
|
|
|
@@ -60,8 +78,15 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
|
60
78
|
@session.find_field("Disabled Checkbox")
|
|
61
79
|
end.to raise_error(Capybara::ElementNotFound)
|
|
62
80
|
end
|
|
63
|
-
end
|
|
64
81
|
|
|
82
|
+
it "should find disabled fields when :all" do
|
|
83
|
+
expect(@session.find_field("Disabled Checkbox", disabled: :all)[:name]).to eq("form[disabled_checkbox]")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should find enabled fields when :all" do
|
|
87
|
+
expect(@session.find_field('Dog', disabled: :all).value).to eq('dog')
|
|
88
|
+
end
|
|
89
|
+
end
|
|
65
90
|
|
|
66
91
|
context 'with :readonly option' do
|
|
67
92
|
it "should find readonly fields when true" do
|
|
@@ -78,4 +103,15 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
|
78
103
|
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
|
|
79
104
|
end
|
|
80
105
|
end
|
|
106
|
+
|
|
107
|
+
context 'with no locator' do
|
|
108
|
+
it 'should use options to find the field' do
|
|
109
|
+
expect(@session.find_field(with: 'dog')['id']).to eq "form_pets_dog"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should accept an optional filter block" do
|
|
114
|
+
# this would be better done with the :with option but this is just a test
|
|
115
|
+
expect(@session.find_field('form[pets][]'){ |node| node.value == 'dog' }[:id]).to eq "form_pets_dog"
|
|
116
|
+
end
|
|
81
117
|
end
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Capybara::SpecHelper.spec '#find_link' do
|
|
2
3
|
before do
|
|
3
4
|
@session.visit('/with_html')
|
|
4
5
|
end
|
|
5
6
|
|
|
6
|
-
it "should find any
|
|
7
|
+
it "should find any link" do
|
|
7
8
|
expect(@session.find_link('foo').text).to eq("ullamco")
|
|
8
9
|
expect(@session.find_link('labore')[:href]).to match %r(/with_simple_html$)
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
context "aria_label attribute with Capybara.enable_aria_label" do
|
|
13
|
+
it "should find when true" do
|
|
14
|
+
Capybara.enable_aria_label = true
|
|
15
|
+
expect(@session.find_link('Go to simple')[:href]).to match %r(/with_simple_html$)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should not find when false" do
|
|
19
|
+
Capybara.enable_aria_label = false
|
|
20
|
+
expect { @session.find_link('Go to simple') }.to raise_error(Capybara::ElementNotFound)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
11
24
|
it "casts to string" do
|
|
12
25
|
expect(@session.find_link(:'foo').text).to eq("ullamco")
|
|
13
26
|
end
|
|
@@ -20,13 +33,19 @@ Capybara::SpecHelper.spec '#find_link' do
|
|
|
20
33
|
|
|
21
34
|
context "with :exact option" do
|
|
22
35
|
it "should accept partial matches when false" do
|
|
23
|
-
expect(@session.find_link('abo', :
|
|
36
|
+
expect(@session.find_link('abo', exact: false).text).to eq("labore")
|
|
24
37
|
end
|
|
25
38
|
|
|
26
39
|
it "should not accept partial matches when true" do
|
|
27
40
|
expect do
|
|
28
|
-
@session.find_link('abo', :
|
|
41
|
+
@session.find_link('abo', exact: true)
|
|
29
42
|
end.to raise_error(Capybara::ElementNotFound)
|
|
30
43
|
end
|
|
31
44
|
end
|
|
45
|
+
|
|
46
|
+
context "without locator" do
|
|
47
|
+
it "should use options" do
|
|
48
|
+
expect(@session.find_link(href: '#anchor').text).to eq "Normal Anchor"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
32
51
|
end
|