capybara 3.2.1 → 3.3.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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +22 -1
  3. data/README.md +1 -1
  4. data/lib/capybara.rb +2 -0
  5. data/lib/capybara/driver/base.rb +5 -1
  6. data/lib/capybara/driver/node.rb +4 -0
  7. data/lib/capybara/helpers.rb +25 -0
  8. data/lib/capybara/minitest.rb +7 -1
  9. data/lib/capybara/minitest/spec.rb +8 -1
  10. data/lib/capybara/node/base.rb +3 -3
  11. data/lib/capybara/node/element.rb +52 -0
  12. data/lib/capybara/node/matchers.rb +33 -0
  13. data/lib/capybara/queries/selector_query.rb +4 -4
  14. data/lib/capybara/queries/style_query.rb +41 -0
  15. data/lib/capybara/rack_test/browser.rb +7 -1
  16. data/lib/capybara/rack_test/node.rb +4 -0
  17. data/lib/capybara/rspec/compound.rb +67 -65
  18. data/lib/capybara/rspec/features.rb +2 -4
  19. data/lib/capybara/rspec/matchers.rb +30 -10
  20. data/lib/capybara/selector.rb +9 -0
  21. data/lib/capybara/selector/css.rb +74 -1
  22. data/lib/capybara/selector/filters/base.rb +2 -1
  23. data/lib/capybara/selector/filters/expression_filter.rb +2 -1
  24. data/lib/capybara/selector/selector.rb +1 -1
  25. data/lib/capybara/selenium/driver.rb +34 -43
  26. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +35 -0
  27. data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +31 -0
  28. data/lib/capybara/selenium/node.rb +17 -20
  29. data/lib/capybara/selenium/nodes/marionette_node.rb +31 -0
  30. data/lib/capybara/server.rb +8 -29
  31. data/lib/capybara/server/checker.rb +38 -0
  32. data/lib/capybara/spec/public/test.js +5 -0
  33. data/lib/capybara/spec/session/all_spec.rb +4 -0
  34. data/lib/capybara/spec/session/assert_style_spec.rb +26 -0
  35. data/lib/capybara/spec/session/click_button_spec.rb +10 -0
  36. data/lib/capybara/spec/session/click_link_spec.rb +11 -0
  37. data/lib/capybara/spec/session/fill_in_spec.rb +2 -0
  38. data/lib/capybara/spec/session/find_link_spec.rb +18 -0
  39. data/lib/capybara/spec/session/find_spec.rb +1 -0
  40. data/lib/capybara/spec/session/first_spec.rb +1 -0
  41. data/lib/capybara/spec/session/has_css_spec.rb +0 -6
  42. data/lib/capybara/spec/session/has_style_spec.rb +25 -0
  43. data/lib/capybara/spec/session/node_spec.rb +34 -0
  44. data/lib/capybara/spec/session/save_page_spec.rb +4 -1
  45. data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -1
  46. data/lib/capybara/spec/session/text_spec.rb +1 -0
  47. data/lib/capybara/spec/session/title_spec.rb +1 -0
  48. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  49. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  50. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -0
  51. data/lib/capybara/spec/session/window/window_spec.rb +20 -0
  52. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  53. data/lib/capybara/spec/session/window/within_window_spec.rb +1 -0
  54. data/lib/capybara/spec/session/within_spec.rb +1 -0
  55. data/lib/capybara/spec/spec_helper.rb +3 -1
  56. data/lib/capybara/spec/test_app.rb +18 -0
  57. data/lib/capybara/spec/views/form.erb +8 -0
  58. data/lib/capybara/spec/views/tables.erb +1 -1
  59. data/lib/capybara/spec/views/with_html.erb +9 -2
  60. data/lib/capybara/spec/views/with_js.erb +4 -0
  61. data/lib/capybara/spec/views/with_namespace.erb +20 -0
  62. data/lib/capybara/version.rb +1 -1
  63. data/lib/capybara/window.rb +11 -0
  64. data/spec/css_splitter_spec.rb +38 -0
  65. data/spec/dsl_spec.rb +1 -1
  66. data/spec/minitest_spec.rb +7 -1
  67. data/spec/minitest_spec_spec.rb +8 -1
  68. data/spec/rack_test_spec.rb +10 -0
  69. data/spec/rspec/shared_spec_matchers.rb +2 -0
  70. data/spec/selenium_spec_chrome.rb +28 -0
  71. data/spec/selenium_spec_chrome_remote.rb +2 -2
  72. data/spec/selenium_spec_marionette.rb +21 -1
  73. data/spec/server_spec.rb +0 -1
  74. data/spec/shared_selenium_session.rb +16 -1
  75. metadata +18 -19
@@ -11,6 +11,7 @@ class MinitestSpecTest < Minitest::Spec
11
11
  before do
12
12
  visit('/form')
13
13
  end
14
+
14
15
  after do
15
16
  Capybara.reset_sessions!
16
17
  end
@@ -115,6 +116,12 @@ class MinitestSpecTest < Minitest::Spec
115
116
  it "handles failures" do
116
117
  page.must_have_select('non_existing_form_title')
117
118
  end
119
+
120
+ it "supports style expectations" do
121
+ skip "Rack test doesn't support style" if Capybara.current_driver == :rack_test
122
+ visit('/with_html')
123
+ find(:css, '#second').must_have_style('display' => 'inline')
124
+ end
118
125
  end
119
126
 
120
127
  RSpec.describe 'capybara/minitest/spec' do
@@ -129,7 +136,7 @@ RSpec.describe 'capybara/minitest/spec' do
129
136
  reporter.start
130
137
  MinitestSpecTest.run reporter, {}
131
138
  reporter.report
132
- expect(output.string).to include("18 runs, 41 assertions, 1 failures, 0 errors, 0 skips")
139
+ expect(output.string).to include("19 runs, 41 assertions, 1 failures, 0 errors, 1 skips")
133
140
  # Make sure error messages are displayed
134
141
  expect(output.string).to include('expected to find visible select box "non_existing_form_title" that is not disabled but there were no matches')
135
142
  end
@@ -16,6 +16,8 @@ skipped_tests = %i[
16
16
  server
17
17
  hover
18
18
  about_scheme
19
+ download
20
+ css
19
21
  ]
20
22
  Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: skipped_tests
21
23
 
@@ -125,6 +127,14 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
125
127
  expect(normal.text).to eq 'banana'
126
128
  end
127
129
  end
130
+
131
+ describe '#style' do
132
+ it "should raise an error" do
133
+ @session.visit('/with_html')
134
+ el = @session.find(:css, '#first')
135
+ expect { el.style('display') }.to raise_error NotImplementedError, /not process CSS/
136
+ end
137
+ end
128
138
  end
129
139
  end
130
140
 
@@ -324,6 +324,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
324
324
 
325
325
  context "with default selector CSS" do
326
326
  before { Capybara.default_selector = :css }
327
+
327
328
  it "fails if has_content? returns false" do
328
329
  expect do
329
330
  expect(page).to have_content('No such Text')
@@ -459,6 +460,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
459
460
 
460
461
  context "with default selector CSS" do
461
462
  before { Capybara.default_selector = :css }
463
+
462
464
  it "fails if has_text? returns false" do
463
465
  expect do
464
466
  expect(page).to have_text('No such Text')
@@ -11,6 +11,34 @@ CHROME_DRIVER = ENV['HEADLESS'] ? :selenium_chrome_headless : :selenium_chrome
11
11
  # Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
12
12
  # end
13
13
 
14
+ Capybara.register_driver :selenium_chrome do |app|
15
+ driver = Capybara::Selenium::Driver.new(app, browser: :chrome)
16
+ # TODO: Fix this when selenium with `download_path =` support is released
17
+ bridge = driver.browser.send(:bridge)
18
+ params = { cmd: 'Page.setDownloadBehavior', params: { behavior: 'allow', downloadPath: Capybara.save_path } }
19
+ command = +'/session/:session_id/chromium/send_command'
20
+ command[':session_id'] = bridge.session_id
21
+ bridge.http.call(:post, command, params)
22
+
23
+ driver
24
+ end
25
+
26
+ Capybara.register_driver :selenium_chrome_headless do |app|
27
+ browser_options = ::Selenium::WebDriver::Chrome::Options.new
28
+ browser_options.args << '--headless'
29
+ browser_options.args << '--disable-gpu' if Gem.win_platform?
30
+ driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
31
+
32
+ # TODO: Fix this when selenium with `download_path =` support is released
33
+ bridge = driver.browser.send(:bridge)
34
+ params = { cmd: 'Page.setDownloadBehavior', params: { behavior: 'allow', downloadPath: Capybara.save_path } }
35
+ command = +'/session/:session_id/chromium/send_command'
36
+ command[':session_id'] = bridge.session_id
37
+ bridge.http.call(:post, command, params)
38
+
39
+ driver
40
+ end
41
+
14
42
  Capybara.register_driver :selenium_chrome_clear_storage do |app|
15
43
  chrome_options = {
16
44
  browser: :chrome,
@@ -39,7 +39,7 @@ module TestSessions
39
39
  Chrome = Capybara::Session.new(CHROME_REMOTE_DRIVER, TestApp)
40
40
  end
41
41
 
42
- skipped_tests = %i[response_headers status_code trigger]
42
+ skipped_tests = %i[response_headers status_code trigger download]
43
43
  # skip window tests when headless for now - closing a window not supported by chromedriver/chrome
44
44
  skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
45
45
 
@@ -51,6 +51,6 @@ RSpec.describe "Capybara::Session with chrome" do
51
51
  include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_REMOTE_DRIVER
52
52
 
53
53
  it 'is considered to be chrome' do
54
- expect(session.driver).to be_chrome
54
+ expect(session.driver.send(:chrome?)).to be_truthy
55
55
  end
56
56
  end
@@ -10,13 +10,19 @@ browser_options.args << '--headless' if ENV['HEADLESS']
10
10
  browser_options.add_preference 'dom.file.createInChild', true
11
11
  # browser_options.add_option("log", {"level": "trace"})
12
12
 
13
+ browser_options.profile = Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
14
+ profile['browser.download.dir'] = Capybara.save_path
15
+ profile['browser.download.folderList'] = 2
16
+ profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv'
17
+ end
18
+
13
19
  Capybara.register_driver :selenium_marionette do |app|
14
20
  # ::Selenium::WebDriver.logger.level = "debug"
15
21
  Capybara::Selenium::Driver.new(
16
22
  app,
17
23
  browser: :firefox,
18
24
  desired_capabilities: { marionette: true, 'moz:webdriverClick': true },
19
- options: browser_options
25
+ options: browser_options,
20
26
  # Get a trace level log from geckodriver
21
27
  # :driver_opts => { args: ['-vv'] }
22
28
  )
@@ -67,6 +73,7 @@ RSpec.describe Capybara::Selenium::Driver do
67
73
  before do
68
74
  @original_browser = @driver.browser
69
75
  end
76
+
70
77
  after do
71
78
  # Ensure browser is actually quit so we don't leave hanging processe
72
79
  RSpec::Mocks.space.proxy_for(@original_browser).reset
@@ -145,3 +152,16 @@ RSpec.describe Capybara::Selenium::Driver do
145
152
  end
146
153
  end
147
154
  end
155
+
156
+ RSpec.describe Capybara::Selenium::Node do
157
+ context "#click" do
158
+ it "warns when attempting on a table row" do
159
+ session = TestSessions::SeleniumMarionette
160
+ session.visit('/tables')
161
+ tr = session.find(:css, '#agent_table tr:first-child')
162
+ allow(tr.base).to receive(:warn)
163
+ tr.click
164
+ expect(tr.base).to have_received(:warn).with(/Clicking the first cell in the row instead/)
165
+ end
166
+ end
167
+ end
@@ -219,7 +219,6 @@ RSpec.describe Capybara::Server do
219
219
  it "should attempt an HTTPS connection if HTTP connection returns #{err}" do
220
220
  app = -> { [200, {}, ['Hello, world']] }
221
221
  ordered_errors = [Errno::ECONNREFUSED, err]
222
- # allow(Net::HTTP).to receive(:start).with(anything, anything, hash_excluding(:use_ssl)).and_yield { raise Errno::ECONNREFUSED }
223
222
  allow(Net::HTTP).to receive(:start).with(anything, anything, hash_excluding(:use_ssl)) do
224
223
  raise ordered_errors.shift
225
224
  end
@@ -180,7 +180,22 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
180
180
  # this is here because it is testing for an XPath that is specific to the algorithm used in the selenium driver
181
181
  session.visit('/path')
182
182
  element = session.find(:link, 'Second Link')
183
- expect(element.path).to eq('/html/body/div[2]/a[1]')
183
+ expect(element.path).to eq('/HTML/BODY/DIV[2]/A[1]')
184
+ end
185
+
186
+ it "handles namespaces" do
187
+ session.visit "/with_namespace"
188
+ rect = session.find(:css, "div svg rect")
189
+ expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")
190
+ expect(session.find(:xpath, rect.path)).to eq rect
191
+ end
192
+
193
+ it "handles case sensitive element names" do
194
+ session.visit "/with_namespace"
195
+ els = session.all(:css, "div *", visible: :all)
196
+ expect { els.map(&:path) }.not_to raise_error
197
+ lg = session.find(:css, "div linearGradient", visible: :all)
198
+ expect(session.find(:xpath, lg.path, visible: :all)).to eq lg
184
199
  end
185
200
  end
186
201
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Walpole
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
12
  - gem-public_cert.pem
13
- date: 2018-06-04 00:00:00.000000000 Z
13
+ date: 2018-06-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable
@@ -212,28 +212,16 @@ dependencies:
212
212
  name: selenium-webdriver
213
213
  requirement: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ">="
216
- - !ruby/object:Gem::Version
217
- version: '3.0'
218
- - - "<"
219
- - !ruby/object:Gem::Version
220
- version: '4.0'
221
- - - "!="
215
+ - - "~>"
222
216
  - !ruby/object:Gem::Version
223
- version: 3.4.1
217
+ version: '3.5'
224
218
  type: :development
225
219
  prerelease: false
226
220
  version_requirements: !ruby/object:Gem::Requirement
227
221
  requirements:
228
- - - ">="
229
- - !ruby/object:Gem::Version
230
- version: '3.0'
231
- - - "<"
232
- - !ruby/object:Gem::Version
233
- version: '4.0'
234
- - - "!="
222
+ - - "~>"
235
223
  - !ruby/object:Gem::Version
236
- version: 3.4.1
224
+ version: '3.5'
237
225
  - !ruby/object:Gem::Dependency
238
226
  name: sinatra
239
227
  requirement: !ruby/object:Gem::Requirement
@@ -297,6 +285,7 @@ files:
297
285
  - lib/capybara/queries/match_query.rb
298
286
  - lib/capybara/queries/selector_query.rb
299
287
  - lib/capybara/queries/sibling_query.rb
288
+ - lib/capybara/queries/style_query.rb
300
289
  - lib/capybara/queries/text_query.rb
301
290
  - lib/capybara/queries/title_query.rb
302
291
  - lib/capybara/rack_test/browser.rb
@@ -320,9 +309,13 @@ files:
320
309
  - lib/capybara/selector/filters/node_filter.rb
321
310
  - lib/capybara/selector/selector.rb
322
311
  - lib/capybara/selenium/driver.rb
312
+ - lib/capybara/selenium/driver_specializations/chrome_driver.rb
313
+ - lib/capybara/selenium/driver_specializations/marionette_driver.rb
323
314
  - lib/capybara/selenium/node.rb
315
+ - lib/capybara/selenium/nodes/marionette_node.rb
324
316
  - lib/capybara/server.rb
325
317
  - lib/capybara/server/animation_disabler.rb
318
+ - lib/capybara/server/checker.rb
326
319
  - lib/capybara/server/middleware.rb
327
320
  - lib/capybara/session.rb
328
321
  - lib/capybara/session/config.rb
@@ -342,6 +335,7 @@ files:
342
335
  - lib/capybara/spec/session/assert_all_of_selectors_spec.rb
343
336
  - lib/capybara/spec/session/assert_current_path_spec.rb
344
337
  - lib/capybara/spec/session/assert_selector_spec.rb
338
+ - lib/capybara/spec/session/assert_style_spec.rb
345
339
  - lib/capybara/spec/session/assert_text_spec.rb
346
340
  - lib/capybara/spec/session/assert_title_spec.rb
347
341
  - lib/capybara/spec/session/attach_file_spec.rb
@@ -384,6 +378,7 @@ files:
384
378
  - lib/capybara/spec/session/has_none_selectors_spec.rb
385
379
  - lib/capybara/spec/session/has_select_spec.rb
386
380
  - lib/capybara/spec/session/has_selector_spec.rb
381
+ - lib/capybara/spec/session/has_style_spec.rb
387
382
  - lib/capybara/spec/session/has_table_spec.rb
388
383
  - lib/capybara/spec/session/has_text_spec.rb
389
384
  - lib/capybara/spec/session/has_title_spec.rb
@@ -443,6 +438,7 @@ files:
443
438
  - lib/capybara/spec/views/with_html.erb
444
439
  - lib/capybara/spec/views/with_html_entities.erb
445
440
  - lib/capybara/spec/views/with_js.erb
441
+ - lib/capybara/spec/views/with_namespace.erb
446
442
  - lib/capybara/spec/views/with_scope.erb
447
443
  - lib/capybara/spec/views/with_simple_html.erb
448
444
  - lib/capybara/spec/views/with_slow_unload.erb
@@ -454,6 +450,7 @@ files:
454
450
  - lib/capybara/window.rb
455
451
  - spec/basic_node_spec.rb
456
452
  - spec/capybara_spec.rb
453
+ - spec/css_splitter_spec.rb
457
454
  - spec/dsl_spec.rb
458
455
  - spec/filter_set_spec.rb
459
456
  - spec/fixtures/capybara.csv
@@ -485,7 +482,9 @@ files:
485
482
  homepage: https://github.com/teamcapybara/capybara
486
483
  licenses:
487
484
  - MIT
488
- metadata: {}
485
+ metadata:
486
+ changelog_uri: https://github.com/teamcapybara/capybara/blob/master/History.md
487
+ source_code_uri: https://github.com/teamcapybara/capybara
489
488
  post_install_message:
490
489
  rdoc_options: []
491
490
  require_paths: