capybara 3.0.3 → 3.1.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 +10 -0
- data/lib/capybara.rb +1 -1
- data/lib/capybara/helpers.rb +1 -1
- data/lib/capybara/minitest/spec.rb +2 -0
- data/lib/capybara/node/actions.rb +45 -5
- data/lib/capybara/queries/match_query.rb +2 -0
- data/lib/capybara/queries/selector_query.rb +3 -4
- data/lib/capybara/queries/text_query.rb +4 -5
- data/lib/capybara/rack_test/node.rb +6 -4
- data/lib/capybara/result.rb +1 -1
- data/lib/capybara/rspec/compound.rb +2 -0
- data/lib/capybara/selector.rb +72 -18
- data/lib/capybara/selector/css.rb +2 -0
- data/lib/capybara/selenium/driver.rb +14 -15
- data/lib/capybara/selenium/node.rb +23 -29
- data/lib/capybara/server.rb +29 -4
- data/lib/capybara/session.rb +12 -13
- data/lib/capybara/spec/session/all_spec.rb +6 -6
- data/lib/capybara/spec/session/{assert_current_path.rb → assert_current_path_spec.rb} +2 -3
- data/lib/capybara/spec/session/{assert_selector.rb → assert_selector_spec.rb} +0 -0
- data/lib/capybara/spec/session/{assert_text.rb → assert_text_spec.rb} +1 -1
- data/lib/capybara/spec/session/{assert_title.rb → assert_title_spec.rb} +0 -0
- data/lib/capybara/spec/session/check_spec.rb +6 -6
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +0 -7
- data/lib/capybara/spec/session/current_url_spec.rb +6 -8
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +2 -0
- data/lib/capybara/spec/session/element/match_css_spec.rb +2 -0
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +2 -0
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +2 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +1 -1
- data/lib/capybara/spec/session/find_field_spec.rb +1 -1
- data/lib/capybara/spec/session/first_spec.rb +12 -12
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -2
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +1 -1
- data/lib/capybara/spec/session/has_button_spec.rb +5 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
- data/lib/capybara/spec/session/has_field_spec.rb +1 -1
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +2 -0
- data/lib/capybara/spec/session/has_selector_spec.rb +8 -0
- data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +0 -0
- data/lib/capybara/spec/session/node_spec.rb +4 -4
- data/lib/capybara/spec/session/reset_session_spec.rb +2 -2
- data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +0 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -1
- data/lib/capybara/spec/session/select_spec.rb +27 -1
- data/lib/capybara/spec/session/selectors_spec.rb +2 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +3 -3
- data/lib/capybara/spec/session/visit_spec.rb +17 -10
- data/lib/capybara/spec/session/window/become_closed_spec.rb +3 -3
- data/lib/capybara/spec/session/window/current_window_spec.rb +2 -2
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +3 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +5 -5
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +3 -3
- data/lib/capybara/spec/session/window/window_spec.rb +24 -9
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -2
- data/lib/capybara/spec/session/window/within_window_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +3 -3
- data/lib/capybara/spec/spec_helper.rb +7 -5
- data/lib/capybara/spec/views/form.erb +9 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +1 -1
- data/spec/capybara_spec.rb +4 -14
- data/spec/dsl_spec.rb +5 -3
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
- data/spec/fixtures/selenium_driver_rspec_success.rb +2 -2
- data/spec/rack_test_spec.rb +8 -6
- data/spec/result_spec.rb +22 -2
- data/spec/rspec/features_spec.rb +4 -2
- data/spec/rspec/scenarios_spec.rb +1 -1
- data/spec/rspec/shared_spec_matchers.rb +7 -4
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_spec.rb +80 -78
- data/spec/selenium_spec_marionette.rb +6 -4
- data/spec/server_spec.rb +40 -2
- data/spec/session_spec.rb +12 -4
- data/spec/shared_selenium_session.rb +106 -84
- metadata +11 -9
@@ -81,7 +81,7 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should not raise an exception if the current_url is nil" do
|
84
|
-
allow_any_instance_of(Capybara::Session).to receive(:current_url)
|
84
|
+
allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil)
|
85
85
|
|
86
86
|
# Without ignore_query option
|
87
87
|
expect do
|
@@ -121,7 +121,7 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "should not raise an exception if the current_url is nil" do
|
124
|
-
allow_any_instance_of(Capybara::Session).to receive(:current_url)
|
124
|
+
allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil)
|
125
125
|
|
126
126
|
# Without ignore_query option
|
127
127
|
expect do
|
@@ -269,7 +269,7 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should support locator-less usage" do
|
272
|
-
expect(@session.has_unchecked_field?(disabled: true, id: "form_disabled_unchecked_checkbox"))
|
272
|
+
expect(@session.has_unchecked_field?(disabled: true, id: "form_disabled_unchecked_checkbox")).to be true
|
273
273
|
expect(@session).to have_unchecked_field(disabled: true, id: "form_disabled_unchecked_checkbox")
|
274
274
|
end
|
275
275
|
end
|
@@ -100,6 +100,14 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
104
|
+
context "datalist" do
|
105
|
+
it "should match options" do
|
106
|
+
@session.visit('/form')
|
107
|
+
expect(@session).to have_selector(:datalist_input, with_options: %w[Jaguar Audi Mercedes])
|
108
|
+
expect(@session).not_to have_selector(:datalist_input, with_options: %w[Ford Chevy])
|
109
|
+
end
|
110
|
+
end
|
103
111
|
end
|
104
112
|
|
105
113
|
Capybara::SpecHelper.spec '#has_no_selector?' do
|
File without changes
|
@@ -98,7 +98,7 @@ Capybara::SpecHelper.spec "node" do
|
|
98
98
|
expect { @session.first('//input[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError)
|
99
99
|
end
|
100
100
|
|
101
|
-
it "should raise if the
|
101
|
+
it "should raise if the textarea is readonly" do
|
102
102
|
expect { @session.first('//textarea[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError)
|
103
103
|
end
|
104
104
|
|
@@ -251,7 +251,7 @@ Capybara::SpecHelper.spec "node" do
|
|
251
251
|
describe "#path" do
|
252
252
|
# Testing for specific XPaths here doesn't make sense since there
|
253
253
|
# are many that can refer to the same element
|
254
|
-
before
|
254
|
+
before do
|
255
255
|
@session.visit('/path')
|
256
256
|
end
|
257
257
|
|
@@ -372,7 +372,7 @@ Capybara::SpecHelper.spec "node" do
|
|
372
372
|
it "should double click an element" do
|
373
373
|
@session.visit('/with_js')
|
374
374
|
@session.find(:css, '#click-test').double_click
|
375
|
-
expect(@session.find(:css, '#has-been-double-clicked')).to
|
375
|
+
expect(@session.find(:css, '#has-been-double-clicked')).to be_truthy
|
376
376
|
end
|
377
377
|
|
378
378
|
it "should allow modifiers", requires: [:js] do
|
@@ -397,7 +397,7 @@ Capybara::SpecHelper.spec "node" do
|
|
397
397
|
it "should right click an element" do
|
398
398
|
@session.visit('/with_js')
|
399
399
|
@session.find(:css, '#click-test').right_click
|
400
|
-
expect(@session.find(:css, '#has-been-right-clicked')).to
|
400
|
+
expect(@session.find(:css, '#has-been-right-clicked')).to be_truthy
|
401
401
|
end
|
402
402
|
|
403
403
|
it "should allow modifiers", requires: [:js] do
|
@@ -18,8 +18,8 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|
18
18
|
expect(@session.current_path).to eq('/foo')
|
19
19
|
|
20
20
|
@session.reset_session!
|
21
|
-
expect([nil, '', 'about:blank']
|
22
|
-
expect(['', nil]
|
21
|
+
expect(@session.current_url).to satisfy('be a blank url') { |url| [nil, '', 'about:blank'].include? url }
|
22
|
+
expect(@session.current_path).to satisfy('be a blank path') { |path| ['', nil].include? path }
|
23
23
|
expect(@session.current_host).to be_nil
|
24
24
|
end
|
25
25
|
|
File without changes
|
@@ -34,9 +34,10 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|
34
34
|
context 'when launchy cannot be required' do
|
35
35
|
it 'prints out a correct warning message', requires: [:screenshot] do
|
36
36
|
file_path = File.join(Dir.tmpdir, 'test.png')
|
37
|
+
allow(@session).to receive(:warn)
|
37
38
|
allow(@session).to receive(:require).with('launchy').and_raise(LoadError)
|
38
|
-
expect(@session).to receive(:warn).with("File saved to #{file_path}.\nPlease install the launchy gem to open the file automatically.")
|
39
39
|
@session.save_and_open_screenshot(file_path)
|
40
|
+
expect(@session).to have_received(:warn).with("File saved to #{file_path}.\nPlease install the launchy gem to open the file automatically.")
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -84,9 +84,35 @@ Capybara::SpecHelper.spec "#select" do
|
|
84
84
|
expect(@session.find_field('Title').value).to eq('Miss')
|
85
85
|
end
|
86
86
|
|
87
|
+
context "input with datalist" do
|
88
|
+
it "should select an option" do
|
89
|
+
@session.select("Audi", from: 'manufacturer')
|
90
|
+
@session.click_button('awesome')
|
91
|
+
expect(extract_results(@session)['manufacturer']).to eq('Audi')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not find an input without a datalist" do
|
95
|
+
expect do
|
96
|
+
@session.select("Thomas", from: 'form_first_name')
|
97
|
+
end.to raise_error(/Unable to find visible input box with datalist completion "form_first_name" that is not disabled/)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not select an option that doesn't exist" do
|
101
|
+
expect do
|
102
|
+
@session.select("Tata", from: 'manufacturer')
|
103
|
+
end.to raise_error(/Unable to find datalist option "Tata"/)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not select a disabled option" do
|
107
|
+
expect do
|
108
|
+
@session.select("Mercedes", from: 'manufacturer')
|
109
|
+
end.to raise_error(/Unable to find datalist option "Mercedes"/)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
87
113
|
context "with a locator that doesn't exist" do
|
88
114
|
it "should raise an error" do
|
89
|
-
msg =
|
115
|
+
msg = /Unable to find visible select box "does not exist" that is not disabled/
|
90
116
|
expect do
|
91
117
|
@session.select('foo', from: 'does not exist')
|
92
118
|
end.to raise_error(Capybara::ElementNotFound, msg)
|
@@ -56,21 +56,21 @@ Capybara::SpecHelper.spec "#uncheck" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should uncheck via clicking the label with :for attribute if possible" do
|
59
|
-
expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to
|
59
|
+
expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to be_truthy
|
60
60
|
@session.uncheck('form_cars_jaguar')
|
61
61
|
@session.click_button('awesome')
|
62
62
|
expect(extract_results(@session)['cars']).not_to include('jaguar')
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should uncheck via clicking the wrapping label if possible" do
|
66
|
-
expect(@session.find(:checkbox, 'form_cars_koenigsegg', checked: true, visible: :hidden)).to
|
66
|
+
expect(@session.find(:checkbox, 'form_cars_koenigsegg', checked: true, visible: :hidden)).to be_truthy
|
67
67
|
@session.uncheck('form_cars_koenigsegg')
|
68
68
|
@session.click_button('awesome')
|
69
69
|
expect(extract_results(@session)['cars']).not_to include('koenigsegg')
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should not click the label if unneeded" do
|
73
|
-
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to
|
73
|
+
expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be_truthy
|
74
74
|
@session.uncheck('form_cars_tesla')
|
75
75
|
@session.click_button('awesome')
|
76
76
|
expect(extract_results(@session)['cars']).not_to include('tesla')
|
@@ -54,11 +54,11 @@ Capybara::SpecHelper.spec '#visit' do
|
|
54
54
|
URI.parse(@session.current_url)
|
55
55
|
end
|
56
56
|
|
57
|
-
before
|
57
|
+
before do
|
58
58
|
Capybara.always_include_port = true
|
59
59
|
end
|
60
60
|
|
61
|
-
after
|
61
|
+
after do
|
62
62
|
Capybara.always_include_port = false
|
63
63
|
end
|
64
64
|
|
@@ -73,52 +73,59 @@ Capybara::SpecHelper.spec '#visit' do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should add the server port to a visited url if no port specified", requires: [:server] do
|
76
|
-
|
76
|
+
allow(@session.driver).to receive(:visit)
|
77
77
|
@session.visit("http://www.example.com")
|
78
|
+
expect(@session.driver).to have_received(:visit).with("http://www.example.com:#{@session.server.port}")
|
78
79
|
end
|
79
80
|
|
80
81
|
it "should not override the visit specified port even if default for scheme", requires: [:server] do
|
81
|
-
|
82
|
+
allow(@session.driver).to receive(:visit)
|
82
83
|
@session.visit('http://www.example.com:80')
|
84
|
+
expect(@session.driver).to have_received(:visit).with("http://www.example.com:80")
|
83
85
|
end
|
84
86
|
|
85
87
|
it "should give preference to app_host port if specified", requires: [:server] do
|
88
|
+
allow(@session.driver).to receive(:visit)
|
86
89
|
Capybara.app_host = "http://www.example.com:6666"
|
87
|
-
expect(@session.driver).to receive(:visit).with("http://www.example.com:6666/random")
|
88
90
|
@session.visit('/random')
|
91
|
+
expect(@session.driver).to have_received(:visit).with("http://www.example.com:6666/random")
|
89
92
|
end
|
90
93
|
|
91
94
|
it "shouldn't override port if no server", requires: [:server] do
|
92
95
|
session = Capybara::Session.new(@session.mode, nil)
|
93
|
-
|
96
|
+
allow(session.driver).to receive(:visit)
|
94
97
|
session.visit("http://www.google.com")
|
98
|
+
expect(session.driver).to have_received(:visit).with("http://www.google.com")
|
95
99
|
end
|
96
100
|
|
97
101
|
it "shouldn't override port if no server but app_host is set", requires: [:server] do
|
98
102
|
session = Capybara::Session.new(@session.mode, nil)
|
99
103
|
Capybara.app_host = "http://www.example.com:6666"
|
100
|
-
|
104
|
+
allow(session.driver).to receive(:visit)
|
101
105
|
session.visit("http://www.google.com")
|
106
|
+
expect(session.driver).to have_received(:visit).with("http://www.google.com")
|
102
107
|
end
|
103
108
|
end
|
104
109
|
|
105
110
|
context "when Capybara.always_include_port is false" do
|
106
|
-
before
|
111
|
+
before do
|
107
112
|
Capybara.always_include_port = false
|
108
113
|
end
|
109
114
|
|
110
115
|
it "shouldn't overwrite port if app_host is set", requires: [:server] do
|
111
116
|
session = Capybara::Session.new(@session.mode, nil)
|
112
117
|
Capybara.app_host = "http://www.example.com:6666"
|
113
|
-
|
118
|
+
allow(session.driver).to receive(:visit)
|
114
119
|
session.visit("http://www.google.com")
|
120
|
+
expect(session.driver).to have_received(:visit).with("http://www.google.com")
|
115
121
|
end
|
116
122
|
|
117
123
|
it "shouldn't overwrite port if port specfified", requires: [:server] do
|
118
124
|
session = Capybara::Session.new(@session.mode, nil)
|
119
125
|
Capybara.app_host = "http://www.example.com:6666"
|
120
|
-
|
126
|
+
allow(session.driver).to receive(:visit)
|
121
127
|
session.visit("http://www.google.com:99")
|
128
|
+
expect(session.driver).to have_received(:visit).with("http://www.google.com:99")
|
122
129
|
end
|
123
130
|
end
|
124
131
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
@other_window = @session.window_opened_by do
|
@@ -9,7 +9,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
after
|
12
|
+
after do
|
13
13
|
@session.document.synchronize(5, errors: [Capybara::CapybaraError]) do
|
14
14
|
raise Capybara::CapybaraError if @session.windows.size != 1
|
15
15
|
end
|
@@ -68,7 +68,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
|
|
68
68
|
Capybara.using_wait_time 0.3 do
|
69
69
|
expect do
|
70
70
|
expect(@other_window).not_to become_closed
|
71
|
-
end
|
71
|
+
end.not_to raise_error
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
end
|
8
|
-
after
|
8
|
+
after do
|
9
9
|
(@session.windows - [@window]).each do |w|
|
10
10
|
@session.switch_to_window w
|
11
11
|
w.close
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
end
|
8
|
-
after
|
8
|
+
after do
|
9
9
|
(@session.windows - [@window]).each do |w|
|
10
10
|
@session.switch_to_window w
|
11
11
|
w.close
|
@@ -16,7 +16,7 @@ Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
|
16
16
|
it 'should open new window with blank url and title' do
|
17
17
|
window = @session.open_new_window
|
18
18
|
@session.switch_to_window(window)
|
19
|
-
expect(['', 'about:blank']
|
19
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
20
20
|
expect(@session.current_url).to eq('about:blank')
|
21
21
|
end
|
22
22
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
|
-
|
7
|
+
@session.assert_selector(:css, 'body.loaded')
|
8
8
|
end
|
9
9
|
|
10
|
-
after
|
10
|
+
after do
|
11
11
|
(@session.windows - [@window]).each do |w|
|
12
12
|
@session.switch_to_window w
|
13
13
|
w.close
|
@@ -32,7 +32,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
32
32
|
window = @session.open_new_window
|
33
33
|
expect(@session.title).to eq('With Windows')
|
34
34
|
@session.switch_to_window(window)
|
35
|
-
expect(['', 'about:blank']
|
35
|
+
expect(@session.title).to satisfy('be a blank title') { |title| ['', 'about:blank'].include? title }
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should raise error when closed window is passed" do
|
@@ -48,7 +48,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
context "with block" do
|
51
|
-
before
|
51
|
+
before do
|
52
52
|
@session.find(:css, '#openTwoWindows').click
|
53
53
|
sleep(1) # wait for the windows to open
|
54
54
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
|
-
|
7
|
+
@session.assert_selector(:css, 'body.loaded')
|
8
8
|
end
|
9
|
-
after
|
9
|
+
after do
|
10
10
|
(@session.windows - [@window]).each do |w|
|
11
11
|
@session.switch_to_window w
|
12
12
|
w.close
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@window = @session.current_window
|
6
6
|
@session.visit('/with_windows')
|
7
7
|
end
|
8
|
-
after
|
8
|
+
after do
|
9
9
|
(@session.windows - [@window]).each do |w|
|
10
10
|
@session.switch_to_window w
|
11
11
|
w.close
|
@@ -14,7 +14,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#exists?' do
|
17
|
-
before
|
17
|
+
before do
|
18
18
|
@other_window = @session.window_opened_by do
|
19
19
|
@session.find(:css, '#openWindow').click
|
20
20
|
end
|
@@ -41,7 +41,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#current?' do
|
44
|
-
before
|
44
|
+
before do
|
45
45
|
@other_window = @session.window_opened_by do
|
46
46
|
@session.find(:css, '#openWindow').click
|
47
47
|
end
|
@@ -61,7 +61,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#close' do
|
64
|
-
before
|
64
|
+
before do
|
65
65
|
@other_window = @session.window_opened_by do
|
66
66
|
@session.find(:css, '#openWindow').click
|
67
67
|
end
|
@@ -109,8 +109,16 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
describe '#resize_to' do
|
112
|
+
before do
|
113
|
+
@initial_size = @session.current_window.size
|
114
|
+
end
|
115
|
+
after do
|
116
|
+
@session.current_window.resize_to(*@initial_size)
|
117
|
+
sleep 0.5
|
118
|
+
end
|
119
|
+
|
112
120
|
it 'should be able to resize window', requires: %i[windows js] do
|
113
|
-
width, height = @
|
121
|
+
width, height = @initial_size
|
114
122
|
@session.current_window.resize_to(width - 100, height - 100)
|
115
123
|
sleep 1
|
116
124
|
expect(@session.current_window.size).to eq([width - 100, height - 100])
|
@@ -132,6 +140,14 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
132
140
|
end
|
133
141
|
|
134
142
|
describe '#maximize' do
|
143
|
+
before do
|
144
|
+
@initial_size = @session.current_window.size
|
145
|
+
end
|
146
|
+
after do
|
147
|
+
@session.current_window.resize_to(*@initial_size)
|
148
|
+
sleep 0.5
|
149
|
+
end
|
150
|
+
|
135
151
|
it 'should be able to maximize window', requires: %i[windows js] do
|
136
152
|
start_width, start_height = 400, 300
|
137
153
|
@session.current_window.resize_to(start_width, start_height)
|
@@ -148,18 +164,17 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|
148
164
|
end
|
149
165
|
|
150
166
|
it 'should stay on current window if invoked not for current window', requires: %i[windows js] do
|
151
|
-
cur_window_size = @session.current_window.size
|
152
167
|
@other_window = @session.window_opened_by do
|
153
168
|
@session.find(:css, '#openWindow').click
|
154
169
|
end
|
155
|
-
|
156
170
|
@other_window.resize_to(400, 300)
|
157
171
|
sleep 0.5
|
158
172
|
@other_window.maximize
|
159
173
|
sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
|
160
174
|
|
161
175
|
expect(@session.current_window).to eq(@window)
|
162
|
-
|
176
|
+
# Maximizing the browser affects all tabs so this may not be valid in real browsers
|
177
|
+
# expect(@session.current_window.size).to eq(@initial_size)
|
163
178
|
|
164
179
|
ow_width, ow_height = @other_window.size
|
165
180
|
expect(ow_width).to be > 400
|