capybara 3.33.0 → 3.35.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +83 -15
  3. data/README.md +0 -2
  4. data/lib/capybara.rb +1 -1
  5. data/lib/capybara/config.rb +4 -6
  6. data/lib/capybara/driver/base.rb +4 -0
  7. data/lib/capybara/helpers.rb +25 -1
  8. data/lib/capybara/minitest.rb +2 -2
  9. data/lib/capybara/minitest/spec.rb +14 -11
  10. data/lib/capybara/node/actions.rb +1 -2
  11. data/lib/capybara/node/base.rb +6 -6
  12. data/lib/capybara/node/element.rb +1 -5
  13. data/lib/capybara/node/finders.rb +7 -6
  14. data/lib/capybara/node/matchers.rb +8 -6
  15. data/lib/capybara/node/simple.rb +5 -1
  16. data/lib/capybara/queries/ancestor_query.rb +1 -1
  17. data/lib/capybara/queries/current_path_query.rb +14 -4
  18. data/lib/capybara/queries/selector_query.rb +32 -17
  19. data/lib/capybara/queries/sibling_query.rb +1 -1
  20. data/lib/capybara/queries/text_query.rb +2 -2
  21. data/lib/capybara/rack_test/browser.rb +7 -3
  22. data/lib/capybara/rack_test/driver.rb +1 -0
  23. data/lib/capybara/rack_test/form.rb +1 -1
  24. data/lib/capybara/rack_test/node.rb +1 -1
  25. data/lib/capybara/registration_container.rb +3 -3
  26. data/lib/capybara/registrations/drivers.rb +18 -12
  27. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  28. data/lib/capybara/registrations/servers.rb +2 -1
  29. data/lib/capybara/result.rb +6 -10
  30. data/lib/capybara/rspec.rb +2 -0
  31. data/lib/capybara/rspec/matcher_proxies.rb +1 -1
  32. data/lib/capybara/rspec/matchers.rb +7 -6
  33. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  34. data/lib/capybara/rspec/matchers/match_style.rb +5 -0
  35. data/lib/capybara/selector.rb +2 -2
  36. data/lib/capybara/selector/builders/css_builder.rb +1 -1
  37. data/lib/capybara/selector/builders/xpath_builder.rb +3 -1
  38. data/lib/capybara/selector/definition.rb +6 -5
  39. data/lib/capybara/selector/definition/button.rb +26 -15
  40. data/lib/capybara/selector/definition/css.rb +1 -1
  41. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  42. data/lib/capybara/selector/definition/element.rb +2 -1
  43. data/lib/capybara/selector/definition/label.rb +1 -1
  44. data/lib/capybara/selector/definition/select.rb +1 -1
  45. data/lib/capybara/selector/definition/table_row.rb +2 -2
  46. data/lib/capybara/selector/filter_set.rb +2 -2
  47. data/lib/capybara/selector/selector.rb +5 -1
  48. data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
  49. data/lib/capybara/selenium/driver.rb +47 -5
  50. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +3 -3
  51. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +3 -3
  52. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +1 -1
  53. data/lib/capybara/selenium/extensions/find.rb +4 -4
  54. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  55. data/lib/capybara/selenium/logger_suppressor.rb +8 -2
  56. data/lib/capybara/selenium/node.rb +6 -3
  57. data/lib/capybara/selenium/nodes/chrome_node.rb +23 -5
  58. data/lib/capybara/selenium/nodes/firefox_node.rb +6 -1
  59. data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
  60. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  61. data/lib/capybara/selenium/patches/logs.rb +4 -4
  62. data/lib/capybara/server/animation_disabler.rb +8 -3
  63. data/lib/capybara/server/middleware.rb +4 -2
  64. data/lib/capybara/session.rb +20 -11
  65. data/lib/capybara/session/matchers.rb +11 -11
  66. data/lib/capybara/spec/public/test.js +6 -1
  67. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  68. data/lib/capybara/spec/session/check_spec.rb +6 -0
  69. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  70. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  71. data/lib/capybara/spec/session/has_button_spec.rb +35 -0
  72. data/lib/capybara/spec/session/has_css_spec.rb +2 -1
  73. data/lib/capybara/spec/session/has_current_path_spec.rb +13 -0
  74. data/lib/capybara/spec/session/has_text_spec.rb +0 -11
  75. data/lib/capybara/spec/session/html_spec.rb +1 -1
  76. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  77. data/lib/capybara/spec/session/node_spec.rb +23 -3
  78. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  79. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  80. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  81. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  82. data/lib/capybara/spec/session/window/window_spec.rb +1 -1
  83. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  84. data/lib/capybara/spec/spec_helper.rb +11 -12
  85. data/lib/capybara/spec/test_app.rb +9 -3
  86. data/lib/capybara/spec/views/form.erb +23 -1
  87. data/lib/capybara/spec/views/with_animation.erb +8 -0
  88. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  89. data/lib/capybara/spec/views/with_js.erb +2 -0
  90. data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
  91. data/lib/capybara/version.rb +1 -1
  92. data/lib/capybara/window.rb +3 -7
  93. data/spec/basic_node_spec.rb +9 -8
  94. data/spec/dsl_spec.rb +1 -1
  95. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  96. data/spec/minitest_spec.rb +2 -1
  97. data/spec/rack_test_spec.rb +15 -5
  98. data/spec/rspec/features_spec.rb +3 -1
  99. data/spec/rspec/scenarios_spec.rb +4 -0
  100. data/spec/rspec/shared_spec_matchers.rb +2 -2
  101. data/spec/rspec_spec.rb +4 -0
  102. data/spec/selector_spec.rb +16 -1
  103. data/spec/selenium_spec_chrome.rb +39 -18
  104. data/spec/selenium_spec_chrome_remote.rb +5 -1
  105. data/spec/selenium_spec_firefox.rb +15 -13
  106. data/spec/server_spec.rb +19 -0
  107. data/spec/shared_selenium_session.rb +74 -1
  108. metadata +47 -13
  109. data/lib/capybara/spec/session/source_spec.rb +0 -0
@@ -229,6 +229,12 @@ Capybara::SpecHelper.spec '#check' do
229
229
  @session.click_button('awesome')
230
230
  expect(extract_results(@session)['cars']).to include('bugatti')
231
231
  end
232
+
233
+ it 'should check via label if multiple labels' do
234
+ expect(@session).to have_field('multi_label_checkbox', checked: false, visible: :hidden)
235
+ @session.check('Label to click', allow_label_click: true)
236
+ expect(@session).to have_field('multi_label_checkbox', checked: true, visible: :hidden)
237
+ end
232
238
  end
233
239
  end
234
240
  end
@@ -38,6 +38,15 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
38
38
  expect(extract_results(@session)['first_name']).to eq('John')
39
39
  end
40
40
 
41
+ context 'with test_id' do
42
+ it 'should click on a button' do
43
+ Capybara.test_id = 'data-test-id'
44
+ @session.visit('/form')
45
+ @session.click_link_or_button('test_id_button')
46
+ expect(extract_results(@session)['first_name']).to eq('John')
47
+ end
48
+ end
49
+
41
50
  context 'with :exact option' do
42
51
  context 'when `false`' do
43
52
  it 'clicks on approximately matching link' do
@@ -22,7 +22,7 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
22
22
 
23
23
  expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
24
24
  expect(@session.current_host).to eq("#{scheme}://#{s.host}") # no port
25
- expect(@session.current_path).to eq(path)
25
+ expect(@session.current_path).to eq(path.split('#')[0])
26
26
  # Server should agree with us
27
27
  expect(@session).to have_content("Current host is #{scheme}://#{s.host}:#{s.port}") if path == '/host'
28
28
  end
@@ -84,6 +84,16 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
84
84
  should_be_on 0, '/landed'
85
85
  end
86
86
 
87
+ it 'maintains fragment' do
88
+ @session.visit("#{bases[0]}/redirect#fragment")
89
+ should_be_on 0, '/landed#fragment'
90
+ end
91
+
92
+ it 'redirects to a fragment' do
93
+ @session.visit("#{bases[0]}/redirect_with_fragment")
94
+ should_be_on 0, '/landed#with_fragment'
95
+ end
96
+
87
97
  it 'is affected by pushState', requires: [:js] do
88
98
  @session.visit('/with_js')
89
99
  @session.execute_script("window.history.pushState({}, '', '/pushed')")
@@ -9,6 +9,8 @@ Capybara::SpecHelper.spec '#has_button?' do
9
9
  expect(@session).to have_button('med')
10
10
  expect(@session).to have_button('crap321')
11
11
  expect(@session).to have_button(:crap321)
12
+ expect(@session).to have_button('button with label element')
13
+ expect(@session).to have_button('button within label element')
12
14
  end
13
15
 
14
16
  it 'should be true for disabled buttons if disabled: true' do
@@ -44,9 +46,25 @@ Capybara::SpecHelper.spec '#has_button?' do
44
46
  expect(@session).to have_button('ARIA button', enable_aria_role: true)
45
47
  end
46
48
 
49
+ it 'should be false for a role=button within a label when enable_aria_role: true' do
50
+ expect(@session).not_to have_button('role=button within label', enable_aria_role: true)
51
+ end
52
+
47
53
  it 'should be false for role=button when enable_aria_role: false' do
48
54
  expect(@session).not_to have_button('ARIA button', enable_aria_role: false)
49
55
  end
56
+
57
+ it 'should be false for a role=button within a label when enable_aria_role: false' do
58
+ expect(@session).not_to have_button('role=button within label', enable_aria_role: false)
59
+ end
60
+
61
+ it 'should not affect other selectors when enable_aria_role: true' do
62
+ expect(@session).to have_button('Click me!', enable_aria_role: true)
63
+ end
64
+
65
+ it 'should not affect other selectors when enable_aria_role: false' do
66
+ expect(@session).to have_button('Click me!', enable_aria_role: false)
67
+ end
50
68
  end
51
69
 
52
70
  Capybara::SpecHelper.spec '#has_no_button?' do
@@ -79,7 +97,24 @@ Capybara::SpecHelper.spec '#has_no_button?' do
79
97
  expect(@session).to have_no_button('ARIA button', enable_aria_role: false)
80
98
  end
81
99
 
100
+ it 'should be true for role=button within a label when enable_aria_role: false' do
101
+ expect(@session).to have_no_button('role=button within label', enable_aria_role: false)
102
+ end
103
+
82
104
  it 'should be false for role=button when enable_aria_role: true' do
83
105
  expect(@session).not_to have_no_button('ARIA button', enable_aria_role: true)
84
106
  end
107
+
108
+ it 'should be true for a role=button within a label when enable_aria_role: true' do
109
+ # label element does not associate with aria button
110
+ expect(@session).to have_no_button('role=button within label', enable_aria_role: true)
111
+ end
112
+
113
+ it 'should not affect other selectors when enable_aria_role: true' do
114
+ expect(@session).to have_no_button('Junk button that does not exist', enable_aria_role: true)
115
+ end
116
+
117
+ it 'should not affect other selectors when enable_aria_role: false' do
118
+ expect(@session).to have_no_button('Junk button that does not exist', enable_aria_role: false)
119
+ end
85
120
  end
@@ -14,8 +14,9 @@ Capybara::SpecHelper.spec '#has_css?' do
14
14
  # This was never a specifically accepted format but it has worked for a
15
15
  # lot of versions.
16
16
  # TODO: Remove in 4.0
17
- expect_any_instance_of(Kernel).to receive(:warn) # rubocop:disable RSpec/AnyInstance
17
+ allow(Capybara::Helpers).to receive(:warn).and_return(nil)
18
18
  expect(@session).to have_css(:p)
19
+ expect(Capybara::Helpers).to have_received(:warn)
19
20
  end
20
21
 
21
22
  it 'should be false if the given selector is not on the page' do
@@ -94,6 +94,13 @@ Capybara::SpecHelper.spec '#has_current_path?' do
94
94
  expect(@session).to have_current_path(nil, ignore_query: true)
95
95
  end.not_to raise_exception
96
96
  end
97
+
98
+ it 'should accept a filter block that receives Addressable::URL' do
99
+ @session.visit('/with_js?a=3&b=defgh')
100
+ expect(@session).to have_current_path('/with_js', ignore_query: true) { |url|
101
+ url.query_values.keys == %w[a b]
102
+ }
103
+ end
97
104
  end
98
105
 
99
106
  Capybara::SpecHelper.spec '#has_no_current_path?' do
@@ -135,4 +142,10 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
135
142
  expect(@session).not_to have_current_path('/with_js', ignore_query: true)
136
143
  end.not_to raise_exception
137
144
  end
145
+
146
+ it 'should accept a filter block that receives Addressable::URL' do
147
+ expect(@session).to have_no_current_path('/with_js', ignore_query: true) { |url|
148
+ !url.query.nil?
149
+ }
150
+ end
138
151
  end
@@ -133,17 +133,6 @@ Capybara::SpecHelper.spec '#has_text?' do
133
133
  expect(@session).to have_text(:visible, with_to_hash, {})
134
134
  end
135
135
  end
136
-
137
- it 'should fail if passed without empty options' do
138
- with_to_hash = Class.new do
139
- def to_s; '42' end
140
- def to_hash; { blah: 'Other hash' } end
141
- end.new
142
- @session.visit('/with_html')
143
- expect do
144
- expect(@session).to have_text(:visible, with_to_hash)
145
- end.to raise_error(ArgumentError)
146
- end
147
136
  end
148
137
 
149
138
  context 'with exact: true option' do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -28,8 +28,8 @@ Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do
28
28
  output(/have_style is deprecated/).to_stderr
29
29
 
30
30
  el = @session.find(:css, '#first')
31
- allow(el).to receive(:warn).and_return(nil)
31
+ allow(Capybara::Helpers).to receive(:warn).and_return(nil)
32
32
  el.has_style?('display' => /^bl/)
33
- expect(el).to have_received(:warn)
33
+ expect(Capybara::Helpers).to have_received(:warn)
34
34
  end
35
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -388,8 +388,8 @@ Capybara::SpecHelper.spec 'node' do
388
388
 
389
389
  describe '#==' do
390
390
  it 'preserve object identity' do
391
- expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/UselessComparison
392
- expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/UselessComparison
391
+ expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
392
+ expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/BinaryOperatorWithIdenticalOperands
393
393
  expect(@session.find('//h1').eql?(@session.find('//h1'))).to be false
394
394
  end
395
395
 
@@ -409,6 +409,17 @@ Capybara::SpecHelper.spec 'node' do
409
409
  element = @session.find(:link, 'Second Link')
410
410
  expect(@session.find(:xpath, element.path)).to eq(element)
411
411
  end
412
+
413
+ it 'reports when element in shadow dom', requires: [:shadow_dom] do
414
+ @session.visit('/with_js')
415
+ shadow = @session.find(:css, '#shadow')
416
+ element = @session.evaluate_script(<<~JS, shadow)
417
+ (function(root){
418
+ return root.shadowRoot.querySelector('span');
419
+ })(arguments[0])
420
+ JS
421
+ expect(element.path).to eq '(: Shadow DOM element - no XPath :)'
422
+ end
412
423
  end
413
424
 
414
425
  describe '#trigger', requires: %i[js trigger] do
@@ -671,6 +682,15 @@ Capybara::SpecHelper.spec 'node' do
671
682
  expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain Some dropped text")]')
672
683
  end
673
684
 
685
+ it 'can drop a pathname' do
686
+ @session.visit('/with_js')
687
+ target = @session.find('//div[@id="drop_html5"]')
688
+ target.drop(
689
+ Pathname.new(with_os_path_separators(File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))))
690
+ )
691
+ expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped file: capybara.jpg")]')
692
+ end
693
+
674
694
  it 'can drop multiple strings' do
675
695
  @session.visit('/with_js')
676
696
  target = @session.find('//div[@id="drop_html5"]')
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -25,6 +25,7 @@ Capybara::SpecHelper.spec '#refresh' do
25
25
  @session.visit('/form')
26
26
  @session.select('Sweden', from: 'form_region')
27
27
  @session.click_button('awesome')
28
+ sleep 2
28
29
  expect do
29
30
  @session.refresh
30
31
  sleep 2
@@ -31,7 +31,7 @@ Capybara::SpecHelper.spec '#save_page' do
31
31
  it 'can store files in a specified directory' do
32
32
  Capybara.save_path = alternative_path
33
33
  @session.save_page
34
- path = Dir.glob(alternative_path + '/capybara-*.html').first
34
+ path = Dir.glob("#{alternative_path}/capybara-*.html").first
35
35
  expect(File.read(path)).to include('Another World')
36
36
  end
37
37
 
@@ -43,14 +43,14 @@ Capybara::SpecHelper.spec '#save_page' do
43
43
  it 'can store files in a specified directory with a given filename' do
44
44
  Capybara.save_path = alternative_path
45
45
  @session.save_page('capybara-001133.html')
46
- path = alternative_path + '/capybara-001133.html'
46
+ path = "#{alternative_path}/capybara-001133.html"
47
47
  expect(File.read(path)).to include('Another World')
48
48
  end
49
49
 
50
50
  it 'can store files in a specified directory with a given relative filename' do
51
51
  Capybara.save_path = alternative_path
52
52
  @session.save_page('tmp/capybara-001144.html')
53
- path = alternative_path + '/tmp/capybara-001144.html'
53
+ path = "#{alternative_path}/tmp/capybara-001144.html"
54
54
  expect(File.read(path)).to include('Another World')
55
55
  end
56
56
 
@@ -63,7 +63,7 @@ Capybara::SpecHelper.spec '#save_page' do
63
63
  it 'returns an absolute path in given directory' do
64
64
  Capybara.save_path = alternative_path
65
65
  result = @session.save_page
66
- path = File.expand_path(Dir.glob(alternative_path + '/capybara-*.html').first, alternative_path)
66
+ path = File.expand_path(Dir.glob("#{alternative_path}/capybara-*.html").first, alternative_path)
67
67
  expect(result).to eq(path)
68
68
  end
69
69
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
3
+ # NOTE: This file uses `sleep` to sync up parts of the tests. This is only implemented like this
4
4
  # because of the methods being tested. In tests using Capybara this type of behavior should be implemented
5
5
  # using Capybara provided assertions with builtin waiting behavior.
6
6
 
@@ -58,7 +58,7 @@ module Capybara
58
58
 
59
59
  def run_specs(session, name, **options, &filter_block)
60
60
  specs = @specs
61
- RSpec.describe Capybara::Session, name, options do # rubocop:disable RSpec/EmptyExampleGroup
61
+ RSpec.describe Capybara::Session, name, options do
62
62
  include Capybara::SpecHelper
63
63
  include Capybara::RSpecMatchers
64
64
 
@@ -72,11 +72,11 @@ module Capybara
72
72
  end
73
73
 
74
74
  before :each, psc: true do
75
- SpecHelper.reset_threadsafe(true, session)
75
+ SpecHelper.reset_threadsafe(bool: true, session: session)
76
76
  end
77
77
 
78
78
  after psc: true do
79
- SpecHelper.reset_threadsafe(false, session)
79
+ SpecHelper.reset_threadsafe(session: session)
80
80
  end
81
81
 
82
82
  before :each, :exact_false do
@@ -84,15 +84,16 @@ module Capybara
84
84
  end
85
85
 
86
86
  specs.each do |spec_name, spec_options, block|
87
- describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup
87
+ describe spec_name, *spec_options do
88
88
  class_eval(&block)
89
89
  end
90
90
  end
91
91
  end
92
92
  end
93
93
 
94
- def reset_threadsafe(bool = false, session = nil)
95
- Capybara::Session.class_variable_set(:@@instance_created, false) # Work around limit on when threadsafe can be changed
94
+ def reset_threadsafe(bool: false, session: nil)
95
+ # Work around limit on when threadsafe can be changed
96
+ Capybara::Session.class_variable_set(:@@instance_created, false) # rubocop:disable Style/ClassVars
96
97
  Capybara.threadsafe = bool
97
98
  session = session.current_session if session.respond_to?(:current_session)
98
99
  session&.instance_variable_set(:@config, nil)
@@ -108,11 +109,9 @@ module Capybara
108
109
  stream.reopen(old_stream)
109
110
  end
110
111
 
111
- def quietly
112
- silence_stream(STDOUT) do
113
- silence_stream(STDERR) do
114
- yield
115
- end
112
+ def quietly(&block)
113
+ silence_stream($stdout) do
114
+ silence_stream($stderr, &block)
116
115
  end
117
116
  end
118
117
 
@@ -132,4 +131,4 @@ module Capybara
132
131
  end
133
132
  end
134
133
 
135
- Dir[File.dirname(__FILE__) + '/session/**/*.rb'].each { |file| require_relative file }
134
+ Dir["#{File.dirname(__FILE__)}/session/**/*.rb"].each { |file| require_relative file }
@@ -7,8 +7,10 @@ require 'yaml'
7
7
 
8
8
  class TestApp < Sinatra::Base
9
9
  class TestAppError < Exception; end # rubocop:disable Lint/InheritException
10
+
10
11
  class TestAppOtherError < Exception # rubocop:disable Lint/InheritException
11
12
  def initialize(string1, msg)
13
+ super()
12
14
  @something = string1
13
15
  @message = msg
14
16
  end
@@ -33,6 +35,10 @@ class TestApp < Sinatra::Base
33
35
  redirect '/redirect_again'
34
36
  end
35
37
 
38
+ get '/redirect_with_fragment' do
39
+ redirect '/landed#with_fragment'
40
+ end
41
+
36
42
  get '/redirect_again' do
37
43
  redirect '/landed'
38
44
  end
@@ -85,11 +91,11 @@ class TestApp < Sinatra::Base
85
91
  end
86
92
 
87
93
  get '/form/get' do
88
- '<pre id="results">' + params[:form].to_yaml + '</pre>'
94
+ %(<pre id="results">#{params[:form].to_yaml}</pre>)
89
95
  end
90
96
 
91
97
  post '/relative' do
92
- '<pre id="results">' + params[:form].to_yaml + '</pre>'
98
+ %(<pre id="results">#{params[:form].to_yaml}</pre>)
93
99
  end
94
100
 
95
101
  get '/favicon.ico' do
@@ -176,7 +182,7 @@ class TestApp < Sinatra::Base
176
182
 
177
183
  post '/form' do
178
184
  self.class.form_post_count += 1
179
- '<pre id="results">' + params[:form].merge('post_count' => self.class.form_post_count).to_yaml + '</pre>'
185
+ %(<pre id="results">#{params[:form].merge('post_count' => self.class.form_post_count).to_yaml}</pre>)
180
186
  end
181
187
 
182
188
  post '/upload_empty' do
@@ -449,13 +449,23 @@ New line after and before textarea tag
449
449
 
450
450
  <p>
451
451
  <input type="button" aria-label="Aria button" name="form[fresh]" id="fresh_btn" value="i am fresh"/>
452
- <input type="submit" name="form[awesome]" id="awe123" title="What an Awesome Button" value="awesome"/>
452
+ <input type="submit" name="form[awesome]" id="awe123" data-test-id="test_id_button" title="What an Awesome Button" value="awesome"/>
453
453
  <input type="submit" name="form[crappy]" id="crap321" value="crappy"/>
454
454
  <input type="image" name="form[okay]" id="okay556" title="Okay 556 Image" value="okay" alt="oh hai thar"/>
455
455
  <button type="submit" id="click_me_123" title="Click Title button" value="click_me">Click me!</button>
456
456
  <button type="submit" name="form[no_value]">No Value!</button>
457
457
  <button id="no_type">No Type!</button>
458
458
  <button><img alt="A horse eating hay"/></button>
459
+ <button id="button_with_label"></button>
460
+ <label for="button_with_label">button with label element</label>
461
+ <label>
462
+ button within label element
463
+ <button></button>
464
+ </label>
465
+ <label>
466
+ role=button within label element
467
+ <span role="button">with other text</span>
468
+ </label>
459
469
  <input type="button" disabled="disabled" value="Disabled button"/>
460
470
  <span role="button">ARIA button</span>
461
471
  </p>
@@ -684,3 +694,15 @@ New line after and before textarea tag
684
694
  <p>
685
695
  <input id="special" {custom}="abcdef" value="custom attribute"/>
686
696
  </p>
697
+
698
+
699
+ <label for="multi_label_checkbox">
700
+ Label to click
701
+ </label>
702
+ <div>Something random that justifies the usage of a separate label</div>
703
+ <label>
704
+ <div>
705
+ <input type="checkbox" id="multi_label_checkbox" style="display: none"/>
706
+ <div>Visual representation of the checkbox</div>
707
+ </div>
708
+ </label>