capybara 2.9.2 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +10 -1
- data/README.md +34 -27
- data/lib/capybara.rb +2 -2
- data/lib/capybara/node/actions.rb +3 -3
- data/lib/capybara/node/base.rb +2 -2
- data/lib/capybara/node/element.rb +1 -1
- data/lib/capybara/node/finders.rb +37 -32
- data/lib/capybara/node/matchers.rb +187 -171
- data/lib/capybara/queries/selector_query.rb +11 -14
- data/lib/capybara/rack_test/driver.rb +3 -3
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/rspec/features.rb +1 -1
- data/lib/capybara/rspec/matchers.rb +31 -22
- data/lib/capybara/selector.rb +2 -2
- data/lib/capybara/selector/selector.rb +22 -0
- data/lib/capybara/session.rb +4 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +4 -4
- data/lib/capybara/spec/session/accept_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/accept_prompt_spec.rb +5 -5
- data/lib/capybara/spec/session/all_spec.rb +27 -27
- data/lib/capybara/spec/session/assert_current_path.rb +2 -2
- data/lib/capybara/spec/session/assert_selector.rb +28 -28
- data/lib/capybara/spec/session/assert_text.rb +20 -20
- data/lib/capybara/spec/session/assert_title.rb +2 -2
- data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
- data/lib/capybara/spec/session/check_spec.rb +5 -5
- data/lib/capybara/spec/session/choose_spec.rb +4 -4
- data/lib/capybara/spec/session/click_button_spec.rb +18 -5
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +6 -6
- data/lib/capybara/spec/session/click_link_spec.rb +13 -13
- data/lib/capybara/spec/session/current_url_spec.rb +2 -2
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +15 -8
- data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
- data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -30
- data/lib/capybara/spec/session/find_button_spec.rb +5 -5
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -2
- data/lib/capybara/spec/session/find_field_spec.rb +11 -7
- data/lib/capybara/spec/session/find_link_spec.rb +2 -2
- data/lib/capybara/spec/session/find_spec.rb +52 -48
- data/lib/capybara/spec/session/first_spec.rb +9 -9
- data/lib/capybara/spec/session/go_back_spec.rb +1 -1
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
- data/lib/capybara/spec/session/has_button_spec.rb +12 -12
- data/lib/capybara/spec/session/has_css_spec.rb +73 -73
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +78 -68
- data/lib/capybara/spec/session/has_link_spec.rb +8 -8
- data/lib/capybara/spec/session/has_select_spec.rb +70 -61
- data/lib/capybara/spec/session/has_selector_spec.rb +28 -28
- data/lib/capybara/spec/session/has_text_spec.rb +6 -6
- data/lib/capybara/spec/session/has_title_spec.rb +2 -2
- data/lib/capybara/spec/session/has_xpath_spec.rb +26 -26
- data/lib/capybara/spec/session/headers.rb +1 -1
- data/lib/capybara/spec/session/html_spec.rb +3 -3
- data/lib/capybara/spec/session/node_spec.rb +15 -15
- data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
- data/lib/capybara/spec/session/response_code.rb +1 -1
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/screenshot_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +30 -30
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +14 -14
- data/lib/capybara/spec/session/visit_spec.rb +2 -2
- data/lib/capybara/spec/session/within_frame_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +6 -6
- data/lib/capybara/spec/spec_helper.rb +1 -1
- data/lib/capybara/spec/test_app.rb +1 -1
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +5 -5
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +1 -1
- data/spec/rack_test_spec.rb +7 -7
- data/spec/rspec/matchers_spec.rb +6 -6
- data/spec/rspec_spec.rb +1 -1
- data/spec/selector_spec.rb +13 -0
- data/spec/selenium_firefox_spec.rb +1 -1
- data/spec/selenium_spec_chrome.rb +1 -1
- data/spec/shared_selenium_session.rb +10 -10
- metadata +2 -2
@@ -6,7 +6,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
6
6
|
|
7
7
|
context "with multiple select" do
|
8
8
|
it "should unselect an option from a select box by id" do
|
9
|
-
@session.unselect('Commando', :
|
9
|
+
@session.unselect('Commando', from: 'form_underwear')
|
10
10
|
@session.click_button('awesome')
|
11
11
|
expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
|
12
12
|
expect(extract_results(@session)['underwear']).not_to include('Commando')
|
@@ -20,27 +20,27 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should unselect an option from a select box by label" do
|
23
|
-
@session.unselect('Commando', :
|
23
|
+
@session.unselect('Commando', from: 'Underwear')
|
24
24
|
@session.click_button('awesome')
|
25
25
|
expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
|
26
26
|
expect(extract_results(@session)['underwear']).not_to include('Commando')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should favour exact matches to option labels" do
|
30
|
-
@session.unselect("Briefs", :
|
30
|
+
@session.unselect("Briefs", from: 'Underwear')
|
31
31
|
@session.click_button('awesome')
|
32
32
|
expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
|
33
33
|
expect(extract_results(@session)['underwear']).not_to include('Briefs')
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should escape quotes" do
|
37
|
-
@session.unselect("Frenchman's Pantalons", :
|
37
|
+
@session.unselect("Frenchman's Pantalons", from: 'Underwear')
|
38
38
|
@session.click_button('awesome')
|
39
39
|
expect(extract_results(@session)['underwear']).not_to include("Frenchman's Pantalons")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "casts to string" do
|
43
|
-
@session.unselect(:"Briefs", :
|
43
|
+
@session.unselect(:"Briefs", from: :'Underwear')
|
44
44
|
@session.click_button('awesome')
|
45
45
|
expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
|
46
46
|
expect(extract_results(@session)['underwear']).not_to include('Briefs')
|
@@ -49,7 +49,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
49
49
|
|
50
50
|
context "with single select" do
|
51
51
|
it "should raise an error" do
|
52
|
-
expect { @session.unselect("English", :
|
52
|
+
expect { @session.unselect("English", from: 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -57,7 +57,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
57
57
|
it "should raise an error" do
|
58
58
|
msg = "Unable to find select box \"does not exist\""
|
59
59
|
expect do
|
60
|
-
@session.unselect('foo', :
|
60
|
+
@session.unselect('foo', from: 'does not exist')
|
61
61
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
62
62
|
end
|
63
63
|
end
|
@@ -66,7 +66,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
66
66
|
it "should raise an error" do
|
67
67
|
msg = "Unable to find option \"Does not Exist\""
|
68
68
|
expect do
|
69
|
-
@session.unselect('Does not Exist', :
|
69
|
+
@session.unselect('Does not Exist', from: 'form_underwear')
|
70
70
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
71
71
|
end
|
72
72
|
end
|
@@ -74,19 +74,19 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
74
74
|
context "with :exact option" do
|
75
75
|
context "when `false`" do
|
76
76
|
it "can match select box approximately" do
|
77
|
-
@session.unselect("Boxerbriefs", :
|
77
|
+
@session.unselect("Boxerbriefs", from: "Under", exact: false)
|
78
78
|
@session.click_button("awesome")
|
79
79
|
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
80
80
|
end
|
81
81
|
|
82
82
|
it "can match option approximately" do
|
83
|
-
@session.unselect("Boxerbr", :
|
83
|
+
@session.unselect("Boxerbr", from: "Underwear", exact: false)
|
84
84
|
@session.click_button("awesome")
|
85
85
|
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "can match option approximately when :from not given" do
|
89
|
-
@session.unselect("Boxerbr", :
|
89
|
+
@session.unselect("Boxerbr", exact: false)
|
90
90
|
@session.click_button("awesome")
|
91
91
|
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
92
92
|
end
|
@@ -95,19 +95,19 @@ Capybara::SpecHelper.spec "#unselect" do
|
|
95
95
|
context "when `true`" do
|
96
96
|
it "can match select box approximately" do
|
97
97
|
expect do
|
98
|
-
@session.unselect("Boxerbriefs", :
|
98
|
+
@session.unselect("Boxerbriefs", from: "Under", exact: true)
|
99
99
|
end.to raise_error(Capybara::ElementNotFound)
|
100
100
|
end
|
101
101
|
|
102
102
|
it "can match option approximately" do
|
103
103
|
expect do
|
104
|
-
@session.unselect("Boxerbr", :
|
104
|
+
@session.unselect("Boxerbr", from: "Underwear", exact: true)
|
105
105
|
end.to raise_error(Capybara::ElementNotFound)
|
106
106
|
end
|
107
107
|
|
108
108
|
it "can match option approximately when :from not given" do
|
109
109
|
expect do
|
110
|
-
@session.unselect("Boxerbr", :
|
110
|
+
@session.unselect("Boxerbr", exact: true)
|
111
111
|
end.to raise_error(Capybara::ElementNotFound)
|
112
112
|
end
|
113
113
|
end
|
@@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#visit' do
|
|
27
27
|
expect(@session).to have_content('Hello world!')
|
28
28
|
end
|
29
29
|
|
30
|
-
it "raises any errors caught inside the server", :
|
30
|
+
it "raises any errors caught inside the server", requires: [:server] do
|
31
31
|
quietly { @session.visit("/error") }
|
32
32
|
expect do
|
33
33
|
@session.visit("/")
|
@@ -65,7 +65,7 @@ Capybara::SpecHelper.spec '#visit' do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context "without a server", :
|
68
|
+
context "without a server", requires: [:server] do
|
69
69
|
it "should respect `app_host`" do
|
70
70
|
serverless_session = Capybara::Session.new(@session.mode, nil)
|
71
71
|
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
Capybara::SpecHelper.spec '#within_frame', :
|
2
|
+
Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
3
3
|
before(:each) do
|
4
4
|
@session.visit('/within_frames')
|
5
5
|
end
|
@@ -58,7 +58,7 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
it "works if the frame is closed", :
|
61
|
+
it "works if the frame is closed", requires: [:frames, :js] do
|
62
62
|
@session.within_frame 'parentFrame' do
|
63
63
|
@session.within_frame 'childFrame' do
|
64
64
|
@session.click_link 'Close Window'
|
@@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should accept additional options" do
|
23
|
-
@session.within(:css, "#for_bar li", :
|
23
|
+
@session.within(:css, "#for_bar li", text: 'With Simple HTML') do
|
24
24
|
@session.click_link('Go')
|
25
25
|
end
|
26
26
|
expect(@session).to have_content('Bar')
|
@@ -114,7 +114,7 @@ Capybara::SpecHelper.spec '#within' do
|
|
114
114
|
expect(extract_results(@session)['first_name']).to eq('Peter')
|
115
115
|
@session.visit('/with_scope')
|
116
116
|
@session.within("//li[contains(.,'Bar')]") do
|
117
|
-
@session.fill_in('First Name', :
|
117
|
+
@session.fill_in('First Name', with: 'Dagobert')
|
118
118
|
@session.click_button('Go')
|
119
119
|
end
|
120
120
|
expect(extract_results(@session)['first_name']).to eq('Dagobert')
|
@@ -128,7 +128,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
|
|
128
128
|
|
129
129
|
it "should restrict scope to a fieldset given by id" do
|
130
130
|
@session.within_fieldset("villain_fieldset") do
|
131
|
-
@session.fill_in("Name", :
|
131
|
+
@session.fill_in("Name", with: 'Goldfinger')
|
132
132
|
@session.click_button("Create")
|
133
133
|
end
|
134
134
|
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
@@ -136,7 +136,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
|
|
136
136
|
|
137
137
|
it "should restrict scope to a fieldset given by legend" do
|
138
138
|
@session.within_fieldset("Villain") do
|
139
|
-
@session.fill_in("Name", :
|
139
|
+
@session.fill_in("Name", with: 'Goldfinger')
|
140
140
|
@session.click_button("Create")
|
141
141
|
end
|
142
142
|
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
@@ -150,7 +150,7 @@ Capybara::SpecHelper.spec '#within_table' do
|
|
150
150
|
|
151
151
|
it "should restrict scope to a fieldset given by id" do
|
152
152
|
@session.within_table("girl_table") do
|
153
|
-
@session.fill_in("Name", :
|
153
|
+
@session.fill_in("Name", with: 'Christmas')
|
154
154
|
@session.click_button("Create")
|
155
155
|
end
|
156
156
|
expect(extract_results(@session)['girl_name']).to eq('Christmas')
|
@@ -158,7 +158,7 @@ Capybara::SpecHelper.spec '#within_table' do
|
|
158
158
|
|
159
159
|
it "should restrict scope to a fieldset given by legend" do
|
160
160
|
@session.within_table("Villain") do
|
161
|
-
@session.fill_in("Name", :
|
161
|
+
@session.fill_in("Name", with: 'Quantum')
|
162
162
|
@session.click_button("Create")
|
163
163
|
end
|
164
164
|
expect(extract_results(@session)['villain_name']).to eq('Quantum')
|
@@ -19,7 +19,7 @@ module Capybara
|
|
19
19
|
module SpecHelper
|
20
20
|
class << self
|
21
21
|
def configure(config)
|
22
|
-
config.filter_run_excluding :
|
22
|
+
config.filter_run_excluding requires: method(:filter).to_proc
|
23
23
|
config.before { Capybara::SpecHelper.reset! }
|
24
24
|
config.after { Capybara::SpecHelper.reset! }
|
25
25
|
# Test in 3.5+ where metadata doesn't autotrigger shared context inclusion - will be only behavior in RSpec 4
|
@@ -351,6 +351,7 @@ New line after and before textarea tag
|
|
351
351
|
<button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>
|
352
352
|
<button type="submit" name="form[no_value]">No Value!</button>
|
353
353
|
<button id="no_type">No Type!</button>
|
354
|
+
<button><img alt="A horse eating hay"/></button>
|
354
355
|
<input type="button" disabled="disabled" value="Disabled button"/>
|
355
356
|
</p>
|
356
357
|
|
data/lib/capybara/version.rb
CHANGED
data/spec/basic_node_spec.rb
CHANGED
@@ -69,13 +69,13 @@ RSpec.describe Capybara do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "allows using matchers with text option" do
|
72
|
-
expect(string).to have_css('h1', :
|
73
|
-
expect(string).not_to have_css('h1', :
|
72
|
+
expect(string).to have_css('h1', text: 'Totally awesome')
|
73
|
+
expect(string).not_to have_css('h1', text: 'Not so awesome')
|
74
74
|
end
|
75
75
|
|
76
76
|
it "allows finding only visible nodes" do
|
77
|
-
expect(string.all(:css, '#secret', :
|
78
|
-
expect(string.all(:css, '#secret', :
|
77
|
+
expect(string.all(:css, '#secret', visible: true)).to be_empty
|
78
|
+
expect(string.all(:css, '#secret', visible: false).size).to eq(1)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "allows finding elements and extracting text from them" do
|
@@ -101,7 +101,7 @@ RSpec.describe Capybara do
|
|
101
101
|
|
102
102
|
it "allows finding elements and checking if they are visible" do
|
103
103
|
expect(string.find('//h1')).to be_visible
|
104
|
-
expect(string.find(:css, "#secret", :
|
104
|
+
expect(string.find(:css, "#secret", visible: false)).not_to be_visible
|
105
105
|
end
|
106
106
|
|
107
107
|
it "allows finding elements and checking if they are disabled" do
|
data/spec/capybara_spec.rb
CHANGED
@@ -47,7 +47,7 @@ RSpec.describe Capybara do
|
|
47
47
|
|
48
48
|
it "should add a new server" do
|
49
49
|
Capybara.register_server :blob do |app, port, host|
|
50
|
-
Rack::Handler::WEBrick.run(app, :
|
50
|
+
Rack::Handler::WEBrick.run(app, Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0))
|
51
51
|
end
|
52
52
|
Capybara.server = :blob
|
53
53
|
session = Capybara::Session.new(:selenium, TestApp.dup)
|
data/spec/dsl_spec.rb
CHANGED
data/spec/rack_test_spec.rb
CHANGED
@@ -5,7 +5,7 @@ module TestSessions
|
|
5
5
|
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
6
6
|
end
|
7
7
|
|
8
|
-
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :
|
8
|
+
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: [
|
9
9
|
:js,
|
10
10
|
:modals,
|
11
11
|
:screenshot,
|
@@ -122,27 +122,27 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
122
122
|
|
123
123
|
describe ':headers option' do
|
124
124
|
it 'should always set headers' do
|
125
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
125
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
126
126
|
@driver.visit('/get_header')
|
127
127
|
expect(@driver.html).to include('foobar')
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'should keep headers on link clicks' do
|
131
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
131
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
132
132
|
@driver.visit('/header_links')
|
133
133
|
@driver.find_xpath('.//a').first.click
|
134
134
|
expect(@driver.html).to include('foobar')
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'should keep headers on form submit' do
|
138
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
138
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
139
139
|
@driver.visit('/header_links')
|
140
140
|
@driver.find_xpath('.//input').first.click
|
141
141
|
expect(@driver.html).to include('foobar')
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should keep headers on redirects' do
|
145
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
145
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
146
146
|
@driver.visit('/get_header_via_redirect')
|
147
147
|
expect(@driver.html).to include('foobar')
|
148
148
|
end
|
@@ -158,7 +158,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
158
158
|
end
|
159
159
|
|
160
160
|
it "is possible to not follow redirects" do
|
161
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
161
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
|
162
162
|
|
163
163
|
@driver.visit('/redirect')
|
164
164
|
expect(@driver.response.header['Location']).to match %r{/redirect_again$}
|
@@ -186,7 +186,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
186
186
|
|
187
187
|
context "with 21 redirect limit" do
|
188
188
|
before do
|
189
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :
|
189
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should follow 21 redirects" do
|
data/spec/rspec/matchers_spec.rb
CHANGED
@@ -25,7 +25,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "passes if matched node count equals expected count" do
|
28
|
-
expect("<h1>Text</h1>").to have_css('h1', :
|
28
|
+
expect("<h1>Text</h1>").to have_css('h1', count: 1)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "fails if matched node count does not equal expected count" do
|
@@ -66,12 +66,12 @@ RSpec.describe Capybara::RSpecMatchers do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "passes if matched node count does not equal expected count" do
|
69
|
-
expect("<h1>Text</h1>").not_to have_css('h1', :
|
69
|
+
expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "fails if matched node count equals expected count" do
|
73
73
|
expect do
|
74
|
-
expect("<h1>Text</h1>").not_to have_css('h1', :
|
74
|
+
expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
|
75
75
|
end.to raise_error(/expected not to find css "h1"/)
|
76
76
|
end
|
77
77
|
end
|
@@ -220,7 +220,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|
220
220
|
|
221
221
|
context "with should" do
|
222
222
|
it "passes if has_selector? returns true" do
|
223
|
-
expect(page).to have_selector('//h1', :
|
223
|
+
expect(page).to have_selector('//h1', text: 'test')
|
224
224
|
end
|
225
225
|
|
226
226
|
it "fails if has_selector? returns false" do
|
@@ -231,7 +231,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|
231
231
|
|
232
232
|
it "includes text in error message" do
|
233
233
|
expect do
|
234
|
-
expect(page).to have_selector("//h1", :
|
234
|
+
expect(page).to have_selector("//h1", text: 'wrong text')
|
235
235
|
end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
|
236
236
|
end
|
237
237
|
end
|
@@ -243,7 +243,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|
243
243
|
|
244
244
|
it "fails if has_no_selector? returns false" do
|
245
245
|
expect do
|
246
|
-
expect(page).not_to have_selector(:css, 'h1', :
|
246
|
+
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
247
247
|
end.to raise_error(%r(expected not to find css "h1" with text "test"))
|
248
248
|
end
|
249
249
|
end
|
data/spec/rspec_spec.rb
CHANGED
@@ -29,7 +29,7 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
it "switches to the javascript driver when giving it as metadata", :
|
32
|
+
it "switches to the javascript driver when giving it as metadata", js: true do
|
33
33
|
expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
|
34
34
|
end
|
35
35
|
|
data/spec/selector_spec.rb
CHANGED
@@ -25,6 +25,7 @@ RSpec.describe Capybara do
|
|
25
25
|
<label for="my_text_input">My Text Input</label>
|
26
26
|
<input type="text" name="form[my_text_input]" placeholder="my text" id="my_text_input"/>
|
27
27
|
<input type="file" id="file" class=".special file"/>
|
28
|
+
<input type="hidden" id="hidden_field" value="this is hidden"/>
|
28
29
|
<a href="#">link</a>
|
29
30
|
<fieldset></fieldset>
|
30
31
|
<select>
|
@@ -51,6 +52,18 @@ RSpec.describe Capybara do
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
55
|
+
describe "adding a selector" do
|
56
|
+
it "can set default visiblity" do
|
57
|
+
Capybara.add_selector :hidden_field do
|
58
|
+
visible :hidden
|
59
|
+
css { |sel| 'input[type="hidden"]' }
|
60
|
+
end
|
61
|
+
|
62
|
+
expect(string).to have_no_css('input[type="hidden"]')
|
63
|
+
expect(string).to have_selector(:hidden_field)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
54
67
|
describe "modify_selector" do
|
55
68
|
it "allows modifying a selector" do
|
56
69
|
el = string.find(:custom_selector, 'a')
|
@@ -21,7 +21,7 @@ skipped_tests = [
|
|
21
21
|
]
|
22
22
|
skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
|
23
23
|
|
24
|
-
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :
|
24
|
+
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
|
25
25
|
|
26
26
|
RSpec.describe "Capybara::Session with firefox" do
|
27
27
|
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_focus
|
@@ -12,7 +12,7 @@ module TestSessions
|
|
12
12
|
Chrome = Capybara::Session.new(:selenium_chrome, TestApp)
|
13
13
|
end
|
14
14
|
|
15
|
-
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :
|
15
|
+
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: [
|
16
16
|
:response_headers,
|
17
17
|
:status_code,
|
18
18
|
:trigger
|
@@ -62,37 +62,37 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
context "#fill_in with { :clear => :backspace } fill_option", :
|
65
|
+
context "#fill_in with { :clear => :backspace } fill_option", requires: [:js] do
|
66
66
|
it 'should fill in a field, replacing an existing value' do
|
67
67
|
@session.visit('/form')
|
68
|
-
@session.fill_in('form_first_name', :
|
68
|
+
@session.fill_in('form_first_name', with: 'Harry',
|
69
69
|
fill_options: { clear: :backspace} )
|
70
70
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should only trigger onchange once' do
|
74
74
|
@session.visit('/with_js')
|
75
|
-
@session.fill_in('with_change_event', :
|
76
|
-
:
|
75
|
+
@session.fill_in('with_change_event', with: 'some value',
|
76
|
+
fill_options: { :clear => :backspace })
|
77
77
|
# click outside the field to trigger the change event
|
78
78
|
@session.find(:css, 'body').click
|
79
|
-
expect(@session.find(:css, '.change_event_triggered', :
|
79
|
+
expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'should trigger change when clearing field' do
|
83
83
|
@session.visit('/with_js')
|
84
|
-
@session.fill_in('with_change_event', :
|
85
|
-
:
|
84
|
+
@session.fill_in('with_change_event', with: '',
|
85
|
+
fill_options: { :clear => :backspace })
|
86
86
|
# click outside the field to trigger the change event
|
87
87
|
@session.find(:css, 'body').click
|
88
|
-
expect(@session).to have_selector(:css, '.change_event_triggered', :
|
88
|
+
expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
context "#fill_in with { clear: :none } fill_options" do
|
93
93
|
it 'should append to content in a field' do
|
94
94
|
@session.visit('/form')
|
95
|
-
@session.fill_in('form_first_name', :
|
95
|
+
@session.fill_in('form_first_name', with: 'Harry',
|
96
96
|
fill_options: { clear: :none} )
|
97
97
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnHarry')
|
98
98
|
end
|
@@ -102,7 +102,7 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
|
102
102
|
it 'should pass the array through to the element' do
|
103
103
|
#this is mainly for use with [[:ctrl, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
|
104
104
|
@session.visit('/form')
|
105
|
-
@session.fill_in('form_first_name', :
|
105
|
+
@session.fill_in('form_first_name', with: 'Harry',
|
106
106
|
fill_options: { clear: [[:shift, 'abc'], :backspace] } )
|
107
107
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnABHarry')
|
108
108
|
end
|