capybara 2.7.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +22 -0
- data/README.md +27 -3
- data/lib/capybara.rb +19 -4
- data/lib/capybara/driver/base.rb +6 -2
- data/lib/capybara/driver/node.rb +13 -5
- data/lib/capybara/helpers.rb +2 -2
- data/lib/capybara/node/actions.rb +116 -17
- data/lib/capybara/node/base.rb +7 -1
- data/lib/capybara/node/element.rb +23 -3
- data/lib/capybara/node/finders.rb +45 -29
- data/lib/capybara/node/matchers.rb +13 -15
- data/lib/capybara/queries/selector_query.rb +22 -5
- data/lib/capybara/queries/text_query.rb +42 -6
- data/lib/capybara/rack_test/node.rb +13 -1
- data/lib/capybara/result.rb +80 -8
- data/lib/capybara/rspec/features.rb +13 -6
- data/lib/capybara/selector.rb +98 -71
- data/lib/capybara/selector/filter_set.rb +46 -0
- data/lib/capybara/selenium/driver.rb +22 -23
- data/lib/capybara/selenium/node.rb +14 -6
- data/lib/capybara/server.rb +20 -10
- data/lib/capybara/session.rb +44 -8
- data/lib/capybara/spec/session/all_spec.rb +4 -4
- data/lib/capybara/spec/session/assert_text.rb +23 -0
- data/lib/capybara/spec/session/check_spec.rb +66 -8
- data/lib/capybara/spec/session/choose_spec.rb +20 -0
- data/lib/capybara/spec/session/click_button_spec.rb +0 -3
- data/lib/capybara/spec/session/click_link_spec.rb +7 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +6 -1
- data/lib/capybara/spec/session/find_button_spec.rb +19 -1
- data/lib/capybara/spec/session/find_field_spec.rb +21 -1
- data/lib/capybara/spec/session/find_link_spec.rb +19 -1
- data/lib/capybara/spec/session/find_spec.rb +32 -4
- data/lib/capybara/spec/session/first_spec.rb +4 -4
- data/lib/capybara/spec/session/has_field_spec.rb +4 -0
- data/lib/capybara/spec/session/has_text_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +24 -3
- data/lib/capybara/spec/session/reset_session_spec.rb +7 -0
- data/lib/capybara/spec/session/selectors_spec.rb +14 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +39 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +4 -2
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +36 -22
- data/lib/capybara/spec/session/within_frame_spec.rb +19 -0
- data/lib/capybara/spec/spec_helper.rb +3 -0
- data/lib/capybara/spec/views/form.erb +34 -6
- data/lib/capybara/spec/views/with_html.erb +5 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +3 -1
- data/lib/capybara/spec/views/with_windows.erb +2 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/capybara_spec.rb +34 -0
- data/spec/rack_test_spec.rb +24 -0
- data/spec/result_spec.rb +25 -0
- data/spec/rspec/features_spec.rb +3 -3
- data/spec/selenium_spec.rb +6 -3
- data/spec/server_spec.rb +2 -2
- metadata +18 -4
@@ -9,6 +9,18 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
9
9
|
expect(@session.find_button('crap321').value).to eq("crappy")
|
10
10
|
end
|
11
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
|
+
|
12
24
|
it "casts to string" do
|
13
25
|
expect(@session.find_button(:'med')[:id]).to eq("mediocre")
|
14
26
|
end
|
@@ -21,7 +33,7 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
21
33
|
|
22
34
|
context "with :exact option" do
|
23
35
|
it "should accept partial matches when false" do
|
24
|
-
expect(@session.find_button('What an Awesome', :exact => false)
|
36
|
+
expect(@session.find_button('What an Awesome', :exact => false).value).to eq("awesome")
|
25
37
|
end
|
26
38
|
|
27
39
|
it "should not accept partial matches when true" do
|
@@ -52,4 +64,10 @@ Capybara::SpecHelper.spec '#find_button' do
|
|
52
64
|
expect(@session.find_button('Disabled button', :disabled => :all).value).to eq("Disabled button")
|
53
65
|
end
|
54
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
|
55
73
|
end
|
@@ -8,6 +8,21 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
8
8
|
expect(@session.find_field('Dog').value).to eq('dog')
|
9
9
|
expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
|
10
10
|
expect(@session.find_field('Region')[:name]).to eq('form[region]')
|
11
|
+
|
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
|
11
26
|
end
|
12
27
|
|
13
28
|
it "casts to string" do
|
@@ -71,7 +86,6 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
71
86
|
end
|
72
87
|
end
|
73
88
|
|
74
|
-
|
75
89
|
context 'with :readonly option' do
|
76
90
|
it "should find readonly fields when true" do
|
77
91
|
expect(@session.find_field('form[readonly_test]', readonly: true)[:id]).to eq 'readonly'
|
@@ -87,4 +101,10 @@ Capybara::SpecHelper.spec '#find_field' do
|
|
87
101
|
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
|
88
102
|
end
|
89
103
|
end
|
104
|
+
|
105
|
+
context 'with no locator' do
|
106
|
+
it 'should use options to find the field' do
|
107
|
+
expect(@session.find_field(with: 'dog')['id']).to eq "form_pets_dog"
|
108
|
+
end
|
109
|
+
end
|
90
110
|
end
|
@@ -4,11 +4,23 @@ Capybara::SpecHelper.spec '#find_link' do
|
|
4
4
|
@session.visit('/with_html')
|
5
5
|
end
|
6
6
|
|
7
|
-
it "should find any
|
7
|
+
it "should find any link" do
|
8
8
|
expect(@session.find_link('foo').text).to eq("ullamco")
|
9
9
|
expect(@session.find_link('labore')[:href]).to match %r(/with_simple_html$)
|
10
10
|
end
|
11
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
|
+
|
12
24
|
it "casts to string" do
|
13
25
|
expect(@session.find_link(:'foo').text).to eq("ullamco")
|
14
26
|
end
|
@@ -30,4 +42,10 @@ Capybara::SpecHelper.spec '#find_link' do
|
|
30
42
|
end.to raise_error(Capybara::ElementNotFound)
|
31
43
|
end
|
32
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
|
33
51
|
end
|
@@ -10,7 +10,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
10
10
|
|
11
11
|
it "should find the first element using the given locator" do
|
12
12
|
expect(@session.find('//h1').text).to eq('This is a test')
|
13
|
-
expect(@session.find("//input[@id='test_field']")
|
13
|
+
expect(@session.find("//input[@id='test_field']").value).to eq('monkey')
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should find the first element using the given locator and options" do
|
@@ -79,7 +79,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
79
79
|
context "with css selectors" do
|
80
80
|
it "should find the first element using the given locator" do
|
81
81
|
expect(@session.find(:css, 'h1').text).to eq('This is a test')
|
82
|
-
expect(@session.find(:css, "input[id='test_field']")
|
82
|
+
expect(@session.find(:css, "input[id='test_field']").value).to eq('monkey')
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should support pseudo selectors" do
|
@@ -90,7 +90,7 @@ Capybara::SpecHelper.spec '#find' do
|
|
90
90
|
context "with xpath selectors" do
|
91
91
|
it "should find the first element using the given locator" do
|
92
92
|
expect(@session.find(:xpath, '//h1').text).to eq('This is a test')
|
93
|
-
expect(@session.find(:xpath, "//input[@id='test_field']")
|
93
|
+
expect(@session.find(:xpath, "//input[@id='test_field']").value).to eq('monkey')
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -165,11 +165,39 @@ Capybara::SpecHelper.spec '#find' do
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
+
context "with alternate filter set" do
|
169
|
+
before do
|
170
|
+
Capybara::Selector::FilterSet.add(:value) do
|
171
|
+
filter(:with) { |node, with| node.value == with.to_s }
|
172
|
+
end
|
173
|
+
|
174
|
+
Capybara.add_selector(:id_with_field_filters) do
|
175
|
+
xpath { |id| XPath.descendant[XPath.attr(:id) == id.to_s] }
|
176
|
+
filter_set(:field)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should allow use of filters from custom filter set" do
|
181
|
+
expect(@session.find(:id, 'test_field', filter_set: :value, with: 'monkey').value).to eq('monkey')
|
182
|
+
expect{ @session.find(:id, 'test_field', filter_set: :value, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should allow use of filter set from a different selector" do
|
186
|
+
expect(@session.find(:id, 'test_field', filter_set: :field, with: 'monkey').value).to eq('monkey')
|
187
|
+
expect{ @session.find(:id, 'test_field', filter_set: :field, with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should allow importing of filter set into selector" do
|
191
|
+
expect(@session.find(:id_with_field_filters, 'test_field', with: 'monkey').value).to eq('monkey')
|
192
|
+
expect{ @session.find(:id_with_field_filters, 'test_field', with: 'not_monkey') }.to raise_error(Capybara::ElementNotFound)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
168
196
|
context "with css as default selector" do
|
169
197
|
before { Capybara.default_selector = :css }
|
170
198
|
it "should find the first element using the given locator" do
|
171
199
|
expect(@session.find('h1').text).to eq('This is a test')
|
172
|
-
expect(@session.find("input[id='test_field']")
|
200
|
+
expect(@session.find("input[id='test_field']").value).to eq('monkey')
|
173
201
|
end
|
174
202
|
after { Capybara.default_selector = :xpath }
|
175
203
|
end
|
@@ -6,7 +6,7 @@ Capybara::SpecHelper.spec '#first' do
|
|
6
6
|
|
7
7
|
it "should find the first element using the given locator" do
|
8
8
|
expect(@session.first('//h1').text).to eq('This is a test')
|
9
|
-
expect(@session.first("//input[@id='test_field']")
|
9
|
+
expect(@session.first("//input[@id='test_field']").value).to eq('monkey')
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should return nil when nothing was found" do
|
@@ -22,14 +22,14 @@ Capybara::SpecHelper.spec '#first' do
|
|
22
22
|
context "with css selectors" do
|
23
23
|
it "should find the first element using the given selector" do
|
24
24
|
expect(@session.first(:css, 'h1').text).to eq('This is a test')
|
25
|
-
expect(@session.first(:css, "input[id='test_field']")
|
25
|
+
expect(@session.first(:css, "input[id='test_field']").value).to eq('monkey')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context "with xpath selectors" do
|
30
30
|
it "should find the first element using the given locator" do
|
31
31
|
expect(@session.first(:xpath, '//h1').text).to eq('This is a test')
|
32
|
-
expect(@session.first(:xpath, "//input[@id='test_field']")
|
32
|
+
expect(@session.first(:xpath, "//input[@id='test_field']").value).to eq('monkey')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,7 +37,7 @@ Capybara::SpecHelper.spec '#first' do
|
|
37
37
|
before { Capybara.default_selector = :css }
|
38
38
|
it "should find the first element using the given locator" do
|
39
39
|
expect(@session.first('h1').text).to eq('This is a test')
|
40
|
-
expect(@session.first("input[id='test_field']")
|
40
|
+
expect(@session.first("input[id='test_field']").value).to eq('monkey')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -16,6 +16,7 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
16
16
|
context 'with value' do
|
17
17
|
it "should be true if a field with the given value is on the page" do
|
18
18
|
expect(@session).to have_field('First Name', :with => 'John')
|
19
|
+
expect(@session).to have_field('First Name', :with => /^Joh/)
|
19
20
|
expect(@session).to have_field('Phone', :with => '+1 555 7021')
|
20
21
|
expect(@session).to have_field('Street', :with => 'Sesame street 66')
|
21
22
|
expect(@session).to have_field('Description', :with => 'Descriptive text goes here')
|
@@ -23,6 +24,7 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
23
24
|
|
24
25
|
it "should be false if the given field is not on the page" do
|
25
26
|
expect(@session).not_to have_field('First Name', :with => 'Peter')
|
27
|
+
expect(@session).not_to have_field('First Name', :with => /eter$/)
|
26
28
|
expect(@session).not_to have_field('Wrong Name', :with => 'John')
|
27
29
|
expect(@session).not_to have_field('Description', :with => 'Monkey')
|
28
30
|
end
|
@@ -30,11 +32,13 @@ Capybara::SpecHelper.spec '#has_field' do
|
|
30
32
|
it "should be true after the field has been filled in with the given value" do
|
31
33
|
@session.fill_in('First Name', :with => 'Jonas')
|
32
34
|
expect(@session).to have_field('First Name', :with => 'Jonas')
|
35
|
+
expect(@session).to have_field('First Name', :with => /ona/)
|
33
36
|
end
|
34
37
|
|
35
38
|
it "should be false after the field has been filled in with a different value" do
|
36
39
|
@session.fill_in('First Name', :with => 'Jonas')
|
37
40
|
expect(@session).not_to have_field('First Name', :with => 'John')
|
41
|
+
expect(@session).not_to have_field('First Name', :with => /John|Paul|George|Ringo/)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -80,7 +80,7 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|
80
80
|
expect(@session).to have_text(:all, 'Some of this text is hidden!')
|
81
81
|
end
|
82
82
|
|
83
|
-
it "should be true if `Capybara.ignore_hidden_elements =
|
83
|
+
it "should be true if `Capybara.ignore_hidden_elements = false` and text is invisible." do
|
84
84
|
Capybara.ignore_hidden_elements = false
|
85
85
|
@session.visit('/with_html')
|
86
86
|
expect(@session).to have_text('Some of this text is hidden!')
|
@@ -280,7 +280,7 @@ Capybara::SpecHelper.spec '#has_no_text?' do
|
|
280
280
|
expect(@session).not_to have_no_text(:all, 'Some of this text is hidden!')
|
281
281
|
end
|
282
282
|
|
283
|
-
it "should be false if `Capybara.ignore_hidden_elements =
|
283
|
+
it "should be false if `Capybara.ignore_hidden_elements = false` and text is invisible." do
|
284
284
|
Capybara.ignore_hidden_elements = false
|
285
285
|
@session.visit('/with_html')
|
286
286
|
expect(@session).not_to have_no_text('Some of this text is hidden!')
|
@@ -19,11 +19,19 @@ Capybara::SpecHelper.spec "node" do
|
|
19
19
|
expect(@session.find(:css, '#second')).to have_no_css('h1')
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "#query_scope" do
|
23
|
+
it "should have a reference to the element the query was evaluated on if there is one" do
|
24
|
+
@node = @session.find(:css, '#first')
|
25
|
+
expect(@node.query_scope).to eq(@node.session.document)
|
26
|
+
expect(@node.find(:css, '#foo').query_scope).to eq(@node)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
22
30
|
describe "#parent" do
|
23
|
-
it "should
|
31
|
+
it "should be deprecated" do
|
24
32
|
@node = @session.find(:css, '#first')
|
25
|
-
expect(@node
|
26
|
-
expect(@node.
|
33
|
+
expect(@node).to receive(:warn).with(/^DEPRECATED:/)
|
34
|
+
expect(@node.parent).to eq(@node.query_scope)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
@@ -409,6 +417,19 @@ Capybara::SpecHelper.spec "node" do
|
|
409
417
|
end
|
410
418
|
end
|
411
419
|
|
420
|
+
context "when #synchronize raises server errors" do
|
421
|
+
it "sets an explanatory exception as the cause of server exceptions", :requires => [:server, :js] do
|
422
|
+
skip "This version of ruby doesn't support exception causes" unless Exception.instance_methods.include? :cause
|
423
|
+
quietly { @session.visit("/error") }
|
424
|
+
expect do
|
425
|
+
@session.find(:css, 'span')
|
426
|
+
end.to raise_error(TestApp::TestAppError) do |e|
|
427
|
+
expect(e.cause).to be_a Capybara::CapybaraError
|
428
|
+
expect(e.cause.message).to match /Your application server raised an error/
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
412
433
|
def be_an_invalid_element_error(session)
|
413
434
|
satisfy { |error| session.driver.invalid_element_errors.any? { |e| error.is_a? e } }
|
414
435
|
end
|
@@ -46,6 +46,13 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
46
46
|
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
|
47
47
|
end
|
48
48
|
|
49
|
+
it "handles already open 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
|
+
|
49
56
|
it "raises any standard errors caught inside the server", :requires => [:server] do
|
50
57
|
quietly { @session.visit("/error") }
|
51
58
|
expect do
|
@@ -32,4 +32,18 @@ Capybara::SpecHelper.spec Capybara::Selector do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
describe "locate_field selectors" do
|
37
|
+
it "can find specifically by id" do
|
38
|
+
expect(@session.find(:field, id: 'customer_email').value).to eq "ben@ben.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can find specifically by name" do
|
42
|
+
expect(@session.find(:field, name: 'form[other_title]')['id']).to eq "form_other_title"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can find specifically by placeholder" do
|
46
|
+
expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq "form_first_name"
|
47
|
+
end
|
48
|
+
end
|
35
49
|
end
|
@@ -38,4 +38,43 @@ Capybara::SpecHelper.spec "#uncheck" do
|
|
38
38
|
end.to raise_error(Capybara::ElementNotFound)
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
context "when checkbox hidden" do
|
43
|
+
context "with Capybara.automatic_label_click == true" do
|
44
|
+
around do |spec|
|
45
|
+
old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
|
46
|
+
spec.run
|
47
|
+
Capybara.automatic_label_click = old_click_label
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should uncheck via clicking the label with :for attribute if possible" do
|
51
|
+
expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to be
|
52
|
+
@session.uncheck('form_cars_jaguar')
|
53
|
+
@session.click_button('awesome')
|
54
|
+
expect(extract_results(@session)['cars']).not_to include('jaguar')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should uncheck via clicking the wrapping label if possible" do
|
58
|
+
expect(@session.find(:checkbox, 'form_cars_koenigsegg', checked: true, visible: :hidden)).to be
|
59
|
+
@session.uncheck('form_cars_koenigsegg')
|
60
|
+
@session.click_button('awesome')
|
61
|
+
expect(extract_results(@session)['cars']).not_to include('koenigsegg')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not click the label if unneeded" do
|
65
|
+
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be
|
66
|
+
@session.uncheck('form_cars_tesla')
|
67
|
+
@session.click_button('awesome')
|
68
|
+
expect(extract_results(@session)['cars']).not_to include('tesla')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise original error when no label available" do
|
72
|
+
expect { @session.uncheck('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find checkbox "form_cars_ariel"')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise error if not allowed to click label" do
|
76
|
+
expect{@session.uncheck('form_cars_jaguar', allow_label_click: false)}.to raise_error(Capybara::ElementNotFound, 'Unable to find checkbox "form_cars_jaguar"')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
41
80
|
end
|
@@ -3,7 +3,9 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
3
3
|
before(:each) do
|
4
4
|
@window = @session.current_window
|
5
5
|
@session.visit('/with_windows')
|
6
|
+
expect(@session).to have_css('body.loaded')
|
6
7
|
end
|
8
|
+
|
7
9
|
after(:each) do
|
8
10
|
(@session.windows - [@window]).each do |w|
|
9
11
|
@session.switch_to_window w
|
@@ -47,7 +49,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
47
49
|
context "with block" do
|
48
50
|
before(:each) do
|
49
51
|
@session.find(:css, '#openTwoWindows').click
|
50
|
-
sleep(
|
52
|
+
sleep(1) # wait for the windows to open
|
51
53
|
end
|
52
54
|
|
53
55
|
it "should be able to switch to current window" do
|
@@ -117,7 +119,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
117
119
|
it "should wait for window to appear" do
|
118
120
|
@session.find(:css, '#openWindowWithTimeout').click
|
119
121
|
expect do
|
120
|
-
@session.switch_to_window { @session.title == 'Title of the first popup'}
|
122
|
+
@session.switch_to_window(wait: 5) { @session.title == 'Title of the first popup'}
|
121
123
|
end.not_to raise_error
|
122
124
|
end
|
123
125
|
end
|
@@ -3,6 +3,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|
3
3
|
before(:each) do
|
4
4
|
@window = @session.current_window
|
5
5
|
@session.visit('/with_windows')
|
6
|
+
expect(@session).to have_css('body.loaded')
|
6
7
|
end
|
7
8
|
after(:each) do
|
8
9
|
(@session.windows - [@window]).each do |w|
|
@@ -73,7 +74,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|
73
74
|
expect do
|
74
75
|
@session.window_opened_by do
|
75
76
|
button.click
|
76
|
-
sleep
|
77
|
+
sleep 1 # It's possible for window_opened_by to be fullfilled before the second window opens
|
77
78
|
end
|
78
79
|
end.to raise_error(Capybara::WindowError, two_windows_message)
|
79
80
|
@session.document.synchronize(2, errors: [Capybara::CapybaraError]) do
|
@@ -86,18 +86,22 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe '#size' do
|
89
|
+
def win_size
|
90
|
+
@session.evaluate_script("[window.outerWidth || window.innerWidth, window.outerHeight || window.innerHeight]")
|
91
|
+
end
|
92
|
+
|
89
93
|
it 'should return size of whole window', requires: [:windows, :js] do
|
90
|
-
expect(@session.current_window.size).to eq
|
94
|
+
expect(@session.current_window.size).to eq win_size
|
91
95
|
end
|
92
96
|
|
93
97
|
it 'should switch to original window if invoked not for current window' do
|
94
98
|
@other_window = @session.window_opened_by do
|
95
99
|
@session.find(:css, '#openWindow').click
|
96
100
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
sleep 1
|
102
|
+
size = @session.within_window(@other_window) do
|
103
|
+
win_size
|
104
|
+
end
|
101
105
|
expect(@other_window.size).to eq(size)
|
102
106
|
expect(@session.current_window).to eq(@window)
|
103
107
|
end
|
@@ -105,10 +109,10 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
105
109
|
|
106
110
|
describe '#resize_to' do
|
107
111
|
it 'should be able to resize window', requires: [:windows, :js] do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
expect(@session.
|
112
|
+
width, height = @session.current_window.size
|
113
|
+
@session.current_window.resize_to(width-100, height-100)
|
114
|
+
sleep 1
|
115
|
+
expect(@session.current_window.size).to eq([width-100, height-100])
|
112
116
|
end
|
113
117
|
|
114
118
|
it 'should stay on current window if invoked not for current window', requires: [:windows, :js] do
|
@@ -120,36 +124,46 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
120
124
|
expect(@session.current_window).to eq(@window)
|
121
125
|
|
122
126
|
# #size returns values larger than availWidth, availHeight with Chromedriver
|
123
|
-
# expect(@other_window.size).to eq([400, 300])
|
124
127
|
@session.within_window(@other_window) do
|
125
|
-
expect(@session.
|
128
|
+
expect(@session.current_window.size).to eq([400,300])
|
129
|
+
# expect(@session.evaluate_script("[window.outerWidth, window.outerHeight]")).to eq([400,300])
|
126
130
|
end
|
127
131
|
end
|
128
132
|
end
|
129
133
|
|
130
134
|
describe '#maximize' do
|
131
135
|
it 'should be able to maximize window', requires: [:windows, :js] do
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
136
|
+
start_width, start_height = 400, 300
|
137
|
+
@session.current_window.resize_to(start_width, start_height)
|
138
|
+
sleep 0.5
|
139
|
+
|
140
|
+
@session.current_window.maximize
|
137
141
|
sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
|
138
|
-
|
142
|
+
|
143
|
+
max_width, max_height = @session.current_window.size
|
144
|
+
|
145
|
+
#maximize behavior is window manage dependant, so just make sure it increases in size
|
146
|
+
expect(max_width).to be > start_width
|
147
|
+
expect(max_height).to be > start_height
|
139
148
|
end
|
140
149
|
|
141
150
|
it 'should stay on current window if invoked not for current window', requires: [:windows, :js] do
|
151
|
+
cur_window_size = @session.current_window.size
|
142
152
|
@other_window = @session.window_opened_by do
|
143
153
|
@session.find(:css, '#openWindow').click
|
144
154
|
end
|
155
|
+
|
156
|
+
@other_window.resize_to(400,300)
|
157
|
+
sleep 0.5
|
145
158
|
@other_window.maximize
|
146
159
|
sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
|
160
|
+
|
147
161
|
expect(@session.current_window).to eq(@window)
|
148
|
-
|
149
|
-
|
150
|
-
@
|
151
|
-
|
152
|
-
|
162
|
+
expect(@session.current_window.size).to eq(cur_window_size)
|
163
|
+
|
164
|
+
ow_width, ow_height = @other_window.size
|
165
|
+
expect(ow_width).to be > 400
|
166
|
+
expect(ow_height).to be > 300
|
153
167
|
end
|
154
168
|
end
|
155
169
|
end
|