capybara 2.18.0 → 3.0.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.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +55 -1
  3. data/README.md +18 -17
  4. data/lib/capybara/config.rb +11 -58
  5. data/lib/capybara/cucumber.rb +2 -3
  6. data/lib/capybara/driver/base.rb +15 -16
  7. data/lib/capybara/driver/node.rb +5 -4
  8. data/lib/capybara/dsl.rb +1 -0
  9. data/lib/capybara/helpers.rb +19 -29
  10. data/lib/capybara/minitest/spec.rb +15 -14
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/node/actions.rb +60 -81
  13. data/lib/capybara/node/base.rb +11 -18
  14. data/lib/capybara/node/document.rb +2 -2
  15. data/lib/capybara/node/document_matchers.rb +8 -8
  16. data/lib/capybara/node/element.rb +30 -40
  17. data/lib/capybara/node/finders.rb +62 -70
  18. data/lib/capybara/node/matchers.rb +50 -71
  19. data/lib/capybara/node/simple.rb +11 -17
  20. data/lib/capybara/queries/ancestor_query.rb +11 -7
  21. data/lib/capybara/queries/base_query.rb +22 -18
  22. data/lib/capybara/queries/current_path_query.rb +8 -24
  23. data/lib/capybara/queries/match_query.rb +3 -7
  24. data/lib/capybara/queries/selector_query.rb +92 -95
  25. data/lib/capybara/queries/sibling_query.rb +4 -4
  26. data/lib/capybara/queries/text_query.rb +35 -35
  27. data/lib/capybara/queries/title_query.rb +8 -11
  28. data/lib/capybara/rack_test/browser.rb +15 -18
  29. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  30. data/lib/capybara/rack_test/driver.rb +6 -10
  31. data/lib/capybara/rack_test/form.rb +50 -40
  32. data/lib/capybara/rack_test/node.rb +93 -63
  33. data/lib/capybara/rails.rb +2 -6
  34. data/lib/capybara/result.rb +22 -22
  35. data/lib/capybara/rspec/compound.rb +5 -10
  36. data/lib/capybara/rspec/features.rb +17 -48
  37. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  38. data/lib/capybara/rspec/matchers.rb +70 -61
  39. data/lib/capybara/rspec.rb +5 -10
  40. data/lib/capybara/selector/css.rb +6 -11
  41. data/lib/capybara/selector/filter.rb +1 -17
  42. data/lib/capybara/selector/filter_set.rb +18 -15
  43. data/lib/capybara/selector/filters/base.rb +7 -6
  44. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  45. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  46. data/lib/capybara/selector/selector.rb +28 -34
  47. data/lib/capybara/selector.rb +129 -117
  48. data/lib/capybara/selenium/driver.rb +131 -125
  49. data/lib/capybara/selenium/node.rb +197 -115
  50. data/lib/capybara/server.rb +3 -2
  51. data/lib/capybara/session/config.rb +47 -67
  52. data/lib/capybara/session/matchers.rb +8 -7
  53. data/lib/capybara/session.rb +138 -224
  54. data/lib/capybara/spec/public/test.js +25 -4
  55. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  56. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  57. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  58. data/lib/capybara/spec/session/all_spec.rb +31 -18
  59. data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
  60. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  61. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  62. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  63. data/lib/capybara/spec/session/assert_text.rb +23 -23
  64. data/lib/capybara/spec/session/assert_title.rb +13 -3
  65. data/lib/capybara/spec/session/attach_file_spec.rb +51 -30
  66. data/lib/capybara/spec/session/body_spec.rb +1 -0
  67. data/lib/capybara/spec/session/check_spec.rb +7 -6
  68. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  69. data/lib/capybara/spec/session/click_button_spec.rb +24 -32
  70. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  71. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  72. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  73. data/lib/capybara/spec/session/current_url_spec.rb +17 -6
  74. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  75. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  76. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  77. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  78. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  79. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  80. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  81. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
  83. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  84. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  85. data/lib/capybara/spec/session/find_field_spec.rb +9 -15
  86. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  87. data/lib/capybara/spec/session/find_spec.rb +37 -31
  88. data/lib/capybara/spec/session/first_spec.rb +60 -33
  89. data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
  90. data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  91. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  92. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  93. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  94. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  95. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  96. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  97. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  98. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  99. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  100. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  101. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  102. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  103. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  104. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  105. data/lib/capybara/spec/session/has_text_spec.rb +9 -13
  106. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  107. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  108. data/lib/capybara/spec/session/headers.rb +2 -1
  109. data/lib/capybara/spec/session/html_spec.rb +1 -0
  110. data/lib/capybara/spec/session/node_spec.rb +91 -56
  111. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  112. data/lib/capybara/spec/session/refresh_spec.rb +6 -2
  113. data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
  114. data/lib/capybara/spec/session/response_code.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  116. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  117. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  118. data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
  119. data/lib/capybara/spec/session/select_spec.rb +20 -20
  120. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  121. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  122. data/lib/capybara/spec/session/text_spec.rb +17 -3
  123. data/lib/capybara/spec/session/title_spec.rb +11 -1
  124. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  125. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  126. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  127. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  128. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  130. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  132. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  133. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  134. data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
  135. data/lib/capybara/spec/session/within_spec.rb +1 -0
  136. data/lib/capybara/spec/spec_helper.rb +34 -18
  137. data/lib/capybara/spec/test_app.rb +17 -9
  138. data/lib/capybara/spec/views/form.erb +7 -0
  139. data/lib/capybara/spec/views/with_html.erb +23 -1
  140. data/lib/capybara/spec/views/within_frames.erb +4 -1
  141. data/lib/capybara/version.rb +2 -1
  142. data/lib/capybara/window.rb +6 -10
  143. data/lib/capybara.rb +28 -25
  144. data/spec/basic_node_spec.rb +1 -0
  145. data/spec/capybara_spec.rb +11 -50
  146. data/spec/dsl_spec.rb +5 -13
  147. data/spec/filter_set_spec.rb +5 -4
  148. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  149. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  150. data/spec/minitest_spec.rb +4 -3
  151. data/spec/minitest_spec_spec.rb +3 -2
  152. data/spec/per_session_config_spec.rb +9 -8
  153. data/spec/rack_test_spec.rb +21 -20
  154. data/spec/result_spec.rb +17 -16
  155. data/spec/rspec/features_spec.rb +17 -14
  156. data/spec/rspec/scenarios_spec.rb +5 -7
  157. data/spec/rspec/shared_spec_matchers.rb +96 -99
  158. data/spec/rspec/views_spec.rb +2 -1
  159. data/spec/rspec_matchers_spec.rb +18 -2
  160. data/spec/rspec_spec.rb +11 -15
  161. data/spec/selector_spec.rb +5 -6
  162. data/spec/selenium_spec_chrome.rb +9 -4
  163. data/spec/selenium_spec_edge.rb +27 -0
  164. data/spec/selenium_spec_ie.rb +31 -0
  165. data/spec/selenium_spec_marionette.rb +28 -12
  166. data/spec/server_spec.rb +33 -33
  167. data/spec/session_spec.rb +2 -1
  168. data/spec/shared_selenium_session.rb +36 -22
  169. data/spec/spec_helper.rb +3 -6
  170. metadata +68 -85
  171. data/lib/capybara/query.rb +0 -7
  172. data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#select" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -13,25 +14,24 @@ Capybara::SpecHelper.spec "#select" do
13
14
  expect(@session.find_field('Title').value).to eq('Miss')
14
15
  end
15
16
 
16
- it "should allow selecting options where there are inexact matches" do
17
+ it "should allow selecting exact options where there are inexact matches", :exact_false do
17
18
  @session.select("Mr", from: 'Title')
18
19
  expect(@session.find_field('Title').value).to eq('Mr')
19
20
  end
20
21
 
21
- it "should allow selecting options where they are the only inexact match" do
22
+ it "should allow selecting options where they are the only inexact match", :exact_false do
22
23
  @session.select("Mis", from: 'Title')
23
24
  expect(@session.find_field('Title').value).to eq('Miss')
24
25
  end
25
26
 
26
- it "should not allow selecting options where they are the only inexact match if `Capybara.exact_options = true`" do
27
- expect_any_instance_of(Kernel).to receive(:warn).with(/^DEPRECATED:/)
28
- Capybara.exact_options = true
27
+ it "should not allow selecting options where they are the only inexact match if `exact: true` is specified" do
28
+ sel = @session.find(:select, 'Title')
29
29
  expect do
30
- @session.select("Mis", from: 'Title')
30
+ sel.select("Mis", exact: true)
31
31
  end.to raise_error(Capybara::ElementNotFound)
32
32
  end
33
33
 
34
- it "should not allow selecting an option if the match is ambiguous" do
34
+ it "should not allow selecting an option if the match is ambiguous", :exact_false do
35
35
  expect do
36
36
  @session.select("M", from: 'Title')
37
37
  end.to raise_error(Capybara::Ambiguous)
@@ -80,7 +80,7 @@ Capybara::SpecHelper.spec "#select" do
80
80
  end
81
81
 
82
82
  it "casts to string" do
83
- @session.select(:"Miss", from: :'Title')
83
+ @session.select(:Miss, from: :Title)
84
84
  expect(@session.find_field('Title').value).to eq('Miss')
85
85
  end
86
86
 
@@ -124,32 +124,32 @@ Capybara::SpecHelper.spec "#select" do
124
124
 
125
125
  context "with multiple select" do
126
126
  it "should return an empty value" do
127
- expect(@session.find_field('Language').value).to eq([])
127
+ expect(@session.find_field('Languages').value).to eq([])
128
128
  end
129
129
 
130
130
  it "should return value of the selected options" do
131
- @session.select("Ruby", from: 'Language')
132
- @session.select("Javascript", from: 'Language')
133
- expect(@session.find_field('Language').value).to include('Ruby', 'Javascript')
131
+ @session.select("Ruby", from: 'Languages')
132
+ @session.select("Javascript", from: 'Languages')
133
+ expect(@session.find_field('Languages').value).to include('Ruby', 'Javascript')
134
134
  end
135
135
 
136
136
  it "should select one option" do
137
- @session.select("Ruby", from: 'Language')
137
+ @session.select("Ruby", from: 'Languages')
138
138
  @session.click_button('awesome')
139
139
  expect(extract_results(@session)['languages']).to eq(['Ruby'])
140
140
  end
141
141
 
142
142
  it "should select multiple options" do
143
- @session.select("Ruby", from: 'Language')
144
- @session.select("Javascript", from: 'Language')
143
+ @session.select("Ruby", from: 'Languages')
144
+ @session.select("Javascript", from: 'Languages')
145
145
  @session.click_button('awesome')
146
146
  expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
147
147
  end
148
148
 
149
149
  it "should remain selected if already selected" do
150
- @session.select("Ruby", from: 'Language')
151
- @session.select("Javascript", from: 'Language')
152
- @session.select("Ruby", from: 'Language')
150
+ @session.select("Ruby", from: 'Languages')
151
+ @session.select("Javascript", from: 'Languages')
152
+ @session.select("Ruby", from: 'Languages')
153
153
  @session.click_button('awesome')
154
154
  expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
155
155
  end
@@ -162,7 +162,7 @@ Capybara::SpecHelper.spec "#select" do
162
162
  context "with :exact option" do
163
163
  context "when `false`" do
164
164
  it "can match select box approximately" do
165
- @session.select("Finish", from: "Loc", exact: false)
165
+ @session.select("Finish", from: "Loc", exact: false)
166
166
  @session.click_button("awesome")
167
167
  expect(extract_results(@session)["locale"]).to eq("fi")
168
168
  end
@@ -195,7 +195,7 @@ Capybara::SpecHelper.spec "#select" do
195
195
 
196
196
  it "can match option approximately when :from not given" do
197
197
  expect do
198
- @session.select("made-up language", exact: true)
198
+ @session.select("made-up language", exact: true)
199
199
  end.to raise_error(Capybara::ElementNotFound)
200
200
  end
201
201
  end
@@ -59,7 +59,7 @@ Capybara::SpecHelper.spec Capybara::Selector do
59
59
  it "can find by class" do
60
60
  expect(@session.find(:field, class: 'confusion-checkbox')['id']).to eq 'confusion_checkbox'
61
61
  expect(@session).to have_selector(:field, class: 'confusion', count: 3)
62
- expect(@session.find(:field, class: ['confusion','confusion-textarea'])['id']).to eq 'confusion_textarea'
62
+ expect(@session.find(:field, class: ['confusion', 'confusion-textarea'])['id']).to eq 'confusion_textarea'
63
63
  end
64
64
  end
65
- end
65
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#sibling' do
3
4
  before do
4
5
  @session.visit('/with_html')
@@ -42,7 +43,6 @@ Capybara::SpecHelper.spec '#sibling' do
42
43
  end
43
44
  end
44
45
 
45
-
46
46
  it "should raise ElementNotFound with a useful default message if nothing was found" do
47
47
  el = @session.find(:css, '#child')
48
48
  expect do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#text' do
3
4
  it "should print the text of the page" do
4
5
  @session.visit('/with_simple_html')
@@ -50,9 +51,22 @@ Capybara::SpecHelper.spec '#text' do
50
51
  after { Capybara.default_selector = :xpath }
51
52
  end
52
53
 
53
- it "should strip whitespace" do
54
+ it "should be correctly normalized when visible" do
55
+ @session.visit('/with_html')
56
+ el = @session.find(:css, '#normalized')
57
+ expect(el.text).to eq "Some text\nMore text\nAnd more text\nEven more text on multiple lines"
58
+ end
59
+
60
+ it "should be a textContent with irrelevant whitespace collapsed when non-visible" do
61
+ @session.visit('/with_html')
62
+ el = @session.find(:css, '#non_visible_normalized', visible: false)
63
+ expect(el.text(:all)).to eq "Some textMore text And more text Even more text on multiple lines"
64
+ end
65
+
66
+ it "should strip correctly" do
54
67
  @session.visit('/with_html')
55
- @session.find(:css, '#second')
56
- expect(@session.find(:css, '#second').text).to match(/\ADuis aute .* text with whitespace .* est laborum\.\z/)
68
+ el = @session.find(:css, '#ws')
69
+ expect(el.text).to eq " "
70
+ expect(el.text(:all)).to eq " "
57
71
  end
58
72
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec '#title' do
3
2
 
3
+ Capybara::SpecHelper.spec '#title' do
4
4
  it "should get the title of the page" do
5
5
  @session.visit('/with_title')
6
6
  expect(@session.title).to eq('Test Title')
@@ -14,4 +14,14 @@ Capybara::SpecHelper.spec '#title' do
14
14
  end
15
15
  after { Capybara.default_selector = :xpath }
16
16
  end
17
+
18
+ context "within iframe", requires: [:frames] do
19
+ it "should get the title of the top level browsing context" do
20
+ @session.visit('/within_frames')
21
+ expect(@session.title).to eq('With Frames')
22
+ @session.within_frame('frameOne') do
23
+ expect(@session.title).to eq('With Frames')
24
+ end
25
+ end
26
+ end
17
27
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#uncheck" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -19,7 +20,7 @@ Capybara::SpecHelper.spec "#uncheck" do
19
20
  end
20
21
 
21
22
  it "casts to string" do
22
- @session.uncheck(:"form_pets_hamster")
23
+ @session.uncheck(:form_pets_hamster)
23
24
  @session.click_button('awesome')
24
25
  expect(extract_results(@session)['pets']).to include('dog')
25
26
  expect(extract_results(@session)['pets']).not_to include('hamster')
@@ -69,11 +70,11 @@ Capybara::SpecHelper.spec "#uncheck" do
69
70
  end
70
71
 
71
72
  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 visible checkbox "form_cars_ariel" that is not disabled')
73
+ expect { @session.uncheck('form_cars_porsche') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_porsche" that is not disabled')
73
74
  end
74
75
 
75
76
  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 visible checkbox "form_cars_jaguar" that is not disabled')
77
+ expect { @session.uncheck('form_cars_jaguar', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_jaguar" that is not disabled')
77
78
  end
78
79
  end
79
80
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec "#unselect" do
3
4
  before do
4
5
  @session.visit('/form')
@@ -40,7 +41,7 @@ Capybara::SpecHelper.spec "#unselect" do
40
41
  end
41
42
 
42
43
  it "casts to string" do
43
- @session.unselect(:"Briefs", from: :'Underwear')
44
+ @session.unselect(:Briefs, from: :Underwear)
44
45
  @session.click_button('awesome')
45
46
  expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
46
47
  expect(extract_results(@session)['underwear']).not_to include('Briefs')
@@ -74,19 +75,19 @@ Capybara::SpecHelper.spec "#unselect" do
74
75
  context "with :exact option" do
75
76
  context "when `false`" do
76
77
  it "can match select box approximately" do
77
- @session.unselect("Boxerbriefs", from: "Under", exact: false)
78
+ @session.unselect("Boxerbriefs", from: "Under", exact: false)
78
79
  @session.click_button("awesome")
79
80
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
80
81
  end
81
82
 
82
83
  it "can match option approximately" do
83
- @session.unselect("Boxerbr", from: "Underwear", exact: false)
84
+ @session.unselect("Boxerbr", from: "Underwear", exact: false)
84
85
  @session.click_button("awesome")
85
86
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
86
87
  end
87
88
 
88
89
  it "can match option approximately when :from not given" do
89
- @session.unselect("Boxerbr", exact: false)
90
+ @session.unselect("Boxerbr", exact: false)
90
91
  @session.click_button("awesome")
91
92
  expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
92
93
  end
@@ -107,7 +108,7 @@ Capybara::SpecHelper.spec "#unselect" do
107
108
 
108
109
  it "can match option approximately when :from not given" do
109
110
  expect do
110
- @session.unselect("Boxerbr", exact: true)
111
+ @session.unselect("Boxerbr", exact: true)
111
112
  end.to raise_error(Capybara::ElementNotFound)
112
113
  end
113
114
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#visit' do
3
4
  it "should fetch a response from the driver with a relative url" do
4
5
  @session.visit('/')
@@ -27,6 +28,14 @@ Capybara::SpecHelper.spec '#visit' do
27
28
  expect(@session).to have_content('Hello world!')
28
29
  end
29
30
 
31
+ it "should fetch a response when sequentially visiting same destination with a target" do
32
+ skip "Chrome/chromedriver has an issue visiting URL with target after visiting same URL without target" if chrome_lt?(65.0, @session)
33
+ @session.visit('/form')
34
+ expect(@session).to have_css('#form_title')
35
+ @session.visit('/form#form_title')
36
+ expect(@session).to have_css('#form_title')
37
+ end
38
+
30
39
  it "raises any errors caught inside the server", requires: [:server] do
31
40
  quietly { @session.visit("/error") }
32
41
  expect do
@@ -40,7 +49,6 @@ Capybara::SpecHelper.spec '#visit' do
40
49
  end
41
50
 
42
51
  context "when Capybara.always_include_port is true" do
43
-
44
52
  let(:root_uri) do
45
53
  @session.visit('/')
46
54
  URI.parse(@session.current_url)
@@ -114,7 +122,6 @@ Capybara::SpecHelper.spec '#visit' do
114
122
  end
115
123
  end
116
124
 
117
-
118
125
  context "without a server", requires: [:server] do
119
126
  it "should respect `app_host`" do
120
127
  serverless_session = Capybara::Session.new(@session.mode, nil)
@@ -188,5 +195,4 @@ Capybara::SpecHelper.spec '#visit' do
188
195
  @session.visit('/get_cookie')
189
196
  expect(@session).to have_content('root cookie')
190
197
  end
191
-
192
198
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
2
+
3
+ Capybara::SpecHelper.spec '#become_closed', requires: %i[windows js] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
5
6
  @session.visit('/with_windows')
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#current_window', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -121,7 +122,7 @@ Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do
121
122
  it "should wait for window to appear" do
122
123
  @session.find(:css, '#openWindowWithTimeout').click
123
124
  expect do
124
- @session.switch_to_window(wait: 5) { @session.title == 'Title of the first popup'}
125
+ @session.switch_to_window(wait: 5) { @session.title == 'Title of the first popup' }
125
126
  end.not_to raise_error
126
127
  end
127
128
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -20,7 +21,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
20
21
  it 'should raise error if value of :wait is less than timeout' do
21
22
  # So large value is used as `driver.window_handles` takes up to 800 ms on Travis
22
23
  Capybara.using_wait_time 2 do
23
- button=@session.find(:css, '#openWindowWithLongerTimeout')
24
+ button = @session.find(:css, '#openWindowWithLongerTimeout')
24
25
  expect do
25
26
  @session.window_opened_by(wait: 0.3) do
26
27
  button.click
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -90,7 +91,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
90
91
  @session.evaluate_script("[window.outerWidth || window.innerWidth, window.outerHeight || window.innerHeight]")
91
92
  end
92
93
 
93
- it 'should return size of whole window', requires: [:windows, :js] do
94
+ it 'should return size of whole window', requires: %i[windows js] do
94
95
  expect(@session.current_window.size).to eq win_size
95
96
  end
96
97
 
@@ -108,15 +109,14 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
108
109
  end
109
110
 
110
111
  describe '#resize_to' do
111
- it 'should be able to resize window', requires: [:windows, :js] do
112
+ it 'should be able to resize window', requires: %i[windows js] do
112
113
  width, height = @session.current_window.size
113
- @session.current_window.resize_to(width-100, height-100)
114
+ @session.current_window.resize_to(width - 100, height - 100)
114
115
  sleep 1
115
- expect(@session.current_window.size).to eq([width-100, height-100])
116
+ expect(@session.current_window.size).to eq([width - 100, height - 100])
116
117
  end
117
118
 
118
- it 'should stay on current window if invoked not for current window', requires: [:windows, :js] do
119
-
119
+ it 'should stay on current window if invoked not for current window', requires: %i[windows js] do
120
120
  @other_window = @session.window_opened_by do
121
121
  @session.find(:css, '#openWindow').click
122
122
  end
@@ -125,35 +125,35 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
125
125
 
126
126
  # #size returns values larger than availWidth, availHeight with Chromedriver
127
127
  @session.within_window(@other_window) do
128
- expect(@session.current_window.size).to eq([400,300])
128
+ expect(@session.current_window.size).to eq([400, 300])
129
129
  # expect(@session.evaluate_script("[window.outerWidth, window.outerHeight]")).to eq([400,300])
130
130
  end
131
131
  end
132
132
  end
133
133
 
134
134
  describe '#maximize' do
135
- it 'should be able to maximize window', requires: [:windows, :js] do
135
+ it 'should be able to maximize window', requires: %i[windows js] do
136
136
  start_width, start_height = 400, 300
137
137
  @session.current_window.resize_to(start_width, start_height)
138
138
  sleep 0.5
139
139
 
140
140
  @session.current_window.maximize
141
- sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
141
+ sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
142
142
 
143
143
  max_width, max_height = @session.current_window.size
144
144
 
145
- #maximize behavior is window manage dependant, so just make sure it increases in size
145
+ # maximize behavior is window manage dependant, so just make sure it increases in size
146
146
  expect(max_width).to be > start_width
147
147
  expect(max_height).to be > start_height
148
148
  end
149
149
 
150
- it 'should stay on current window if invoked not for current window', requires: [:windows, :js] do
150
+ it 'should stay on current window if invoked not for current window', requires: %i[windows js] do
151
151
  cur_window_size = @session.current_window.size
152
152
  @other_window = @session.window_opened_by do
153
153
  @session.find(:css, '#openWindow').click
154
154
  end
155
155
 
156
- @other_window.resize_to(400,300)
156
+ @other_window.resize_to(400, 300)
157
157
  sleep 0.5
158
158
  @other_window.maximize
159
159
  sleep 0.5 # The timing on maximize is finicky on Travis -- wait a bit for maximize to occur
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#windows', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -25,8 +26,6 @@ Capybara::SpecHelper.spec '#windows', requires: [:windows] do
25
26
  titles = @session.windows.map do |window|
26
27
  @session.within_window(window) { @session.title }
27
28
  end
28
- expect(titles).to match_array([
29
- 'With Windows', 'Title of the first popup', 'Title of popup two'
30
- ])
29
+ expect(titles).to match_array(['With Windows', 'Title of the first popup', 'Title of popup two'])
31
30
  end
32
31
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
3
4
  before(:each) do
4
5
  @window = @session.current_window
@@ -19,16 +20,15 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
19
20
 
20
21
  context "with an instance of Capybara::Window" do
21
22
  it "should not invoke driver#switch_to_window when given current window" do
22
- # switch_to_window is invoked in after hook
23
- expect(@session.driver).to receive(:switch_to_window).exactly(3).times.and_call_original
23
+ allow(@session.driver).to receive(:switch_to_window).and_call_original
24
24
  @session.within_window @window do
25
25
  expect(@session.title).to eq('With Windows')
26
26
  end
27
+ expect(@session.driver).not_to have_received(:switch_to_window)
27
28
  end
28
29
 
29
30
  it "should be able to switch to another window" do
30
31
  window = (@session.windows - [@window]).first
31
- expect(@session.driver).to receive(:switch_to_window).exactly(5).times.and_call_original
32
32
  @session.within_window window do
33
33
  expect(@session).to have_title(/Title of the first popup|Title of popup two/)
34
34
  end
@@ -38,8 +38,8 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
38
38
  it "returns value from the block" do
39
39
  window = (@session.windows - [@window]).first
40
40
  value = @session.within_window window do
41
- 43252003274489856000
42
- end
41
+ 43252003274489856000
42
+ end
43
43
  expect(value).to eq(43252003274489856000)
44
44
  end
45
45
 
@@ -57,7 +57,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
57
57
  expect(@session.send(:scopes)).to eq([nil])
58
58
  end
59
59
 
60
- it "should leave correct scopes after execution in case of error", requires: [:windows, :frames] do
60
+ it "should leave correct scopes after execution in case of error", requires: %i[windows frames] do
61
61
  window = (@session.windows - [@window]).first
62
62
  expect do
63
63
  @session.within_frame 'frameOne' do
@@ -87,25 +87,25 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
87
87
 
88
88
  context "with lambda" do
89
89
  it "should find the div in another window" do
90
- @session.within_window(->{ @session.title == 'Title of the first popup'}) do
90
+ @session.within_window(-> { @session.title == 'Title of the first popup' }) do
91
91
  expect(@session).to have_css('#divInPopupOne')
92
92
  end
93
93
  end
94
94
 
95
95
  it "should find divs in both windows" do
96
- @session.within_window(->{ @session.title == 'Title of popup two'}) do
96
+ @session.within_window(-> { @session.title == 'Title of popup two' }) do
97
97
  expect(@session).to have_css('#divInPopupTwo')
98
98
  end
99
- @session.within_window(->{ @session.title == 'Title of the first popup'}) do
99
+ @session.within_window(-> { @session.title == 'Title of the first popup' }) do
100
100
  expect(@session).to have_css('#divInPopupOne')
101
101
  end
102
102
  expect(@session.title).to eq('With Windows')
103
103
  end
104
104
 
105
105
  it "should be able to nest within_window" do
106
- @session.within_window(->{ @session.title == 'Title of popup two'}) do
106
+ @session.within_window(-> { @session.title == 'Title of popup two' }) do
107
107
  expect(@session).to have_css('#divInPopupTwo')
108
- @session.within_window(->{ @session.title == 'Title of the first popup'}) do
108
+ @session.within_window(-> { @session.title == 'Title of the first popup' }) do
109
109
  expect(@session).to have_css('#divInPopupOne')
110
110
  end
111
111
  expect(@session).to have_css('#divInPopupTwo')
@@ -119,7 +119,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
119
119
  it "should work inside a normal scope" do
120
120
  expect(@session).to have_css('#openWindow')
121
121
  @session.within(:css, '#scope') do
122
- @session.within_window(->{ @session.title == 'Title of the first popup'}) do
122
+ @session.within_window(-> { @session.title == 'Title of the first popup' }) do
123
123
  expect(@session).to have_css('#divInPopupOne')
124
124
  end
125
125
  expect(@session).to have_content('My scoped content')
@@ -129,7 +129,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
129
129
 
130
130
  it "should raise error if window wasn't found" do
131
131
  expect do
132
- @session.within_window(->{ @session.title == 'Invalid title'}) do
132
+ @session.within_window(-> { @session.title == 'Invalid title' }) do
133
133
  expect(@session).to have_css('#divInPopupOne')
134
134
  end
135
135
  end.to raise_error(Capybara::WindowError, "Could not find a window matching block/lambda")
@@ -139,15 +139,13 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
139
139
  end
140
140
 
141
141
  it "returns value from the block" do
142
- value = @session.within_window(->{ @session.title == 'Title of popup two'}) do
143
- 42
144
- end
142
+ value = @session.within_window(-> { @session.title == 'Title of popup two' }) { 42 }
145
143
  expect(value).to eq(42)
146
144
  end
147
145
 
148
146
  it "should switch back if exception was raised inside block" do
149
147
  expect do
150
- @session.within_window(->{ @session.title == 'Title of popup two'}) do
148
+ @session.within_window(-> { @session.title == 'Title of popup two' }) do
151
149
  raise 'some error'
152
150
  end
153
151
  end.to raise_error(StandardError, 'some error')
@@ -155,58 +153,4 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
155
153
  expect(@session.send(:scopes)).to eq([nil])
156
154
  end
157
155
  end
158
-
159
- context "with string" do
160
- it "should warn" do
161
- expect(@session).to receive(:warn).with(/DEPRECATION WARNING/).and_call_original
162
- @session.within_window('firstPopup') {}
163
- end
164
-
165
- it "should find window by handle" do
166
- window = (@session.windows - [@window]).first
167
- @session.within_window window.handle do
168
- expect(@session).to have_title(/Title of the first popup|Title of popup two/)
169
- end
170
- end
171
-
172
- it "should find the div in firstPopup" do
173
- @session.within_window("firstPopup") do
174
- expect(@session.find("//*[@id='divInPopupOne']").text).to eq 'This is the text of divInPopupOne'
175
- end
176
- end
177
- it "should find the div in secondPopup" do
178
- @session.within_window("secondPopup") do
179
- expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
180
- end
181
- end
182
- it "should find the divs in both popups" do
183
- @session.within_window("secondPopup") do
184
- expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
185
- end
186
- @session.within_window("firstPopup") do
187
- expect(@session.find("//*[@id='divInPopupOne']").text).to eq 'This is the text of divInPopupOne'
188
- end
189
- end
190
- it "should find the div in the main window after finding a div in a popup" do
191
- @session.within_window("secondPopup") do
192
- expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
193
- end
194
- expect(@session.find("//*[@id='doesNotOpenWindows']").text).to eq 'Does not open windows'
195
- end
196
- it "should reset scope when switching windows" do
197
- @session.within(:css, '#doesNotOpenWindows') do
198
- @session.within_window("secondPopup") do
199
- expect(@session.find("//*[@id='divInPopupTwo']").text).to eq 'This is the text of divInPopupTwo'
200
- end
201
- end
202
- end
203
- it "should switch back if exception was raised inside block" do
204
- expect do
205
- @session.within_window('secondPopup') do
206
- raise 'some error'
207
- end
208
- end.to raise_error(StandardError, 'some error')
209
- expect(@session.current_window).to eq(@window)
210
- end
211
- end
212
156
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#within' do
3
4
  before do
4
5
  @session.visit('/with_scope')