capybara 3.23.0 → 3.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99599c60a1bafbd60b15e476dbaff54e5692358aed4e55908a40d537ebf00194
4
- data.tar.gz: 26cb00377b6c80746e29838c8a22630a90786d73fa588e0ab9b3dd09fb7de9b9
3
+ metadata.gz: 2ea1da81bd27199aadc0d73d61e33b7ff0ea9911114acc375ea2e6f798a49eb4
4
+ data.tar.gz: 30279a8a5ab221ae029bc95625c7c82ad11cdf68d91ef6be33e7a0b022268537
5
5
  SHA512:
6
- metadata.gz: ea61766410acfe21525a56d25d44960a3c178b4d2c210bbc1f28bcc6c925f2bcbeeb1fd821a3618f94a775d7054291b3b831e411a75a0cb1ad6dd3ca517c0e91
7
- data.tar.gz: de3a8a91967058710ebc0e30953cb22ea1fae30f5475ab32599a0c088ce032cba385721fe79a84cb5f81597bfc8b230afd5dabfb8e28391c1d7102453e251832
6
+ metadata.gz: 0b8d7f760540297a204ae5eb0dac8b9450e8961652de87d543ae114edb9af6a48219db7c55a40e004d49847431ef545cc5628a6bbde858e58921209f984852d2
7
+ data.tar.gz: 56d10157a97fd98f7e2e23c98fc21f0dc0f70f53338a271c9fa22b639648d919134fe1c7c803be43f435a9618d49e2517ccce5d207139635c49d9f6f18a66bd6
data/History.md CHANGED
@@ -1,3 +1,20 @@
1
+ # Version 3.24.0
2
+ Release date: 2079-06-13
3
+
4
+ ### Added
5
+
6
+ * Log access when using the Selenium driver with Chrome 75 in W3C mode has been reenabled.
7
+
8
+ ### Changed
9
+
10
+ * Selenium driver now selects all current content and then sends keys rather than clearing field by JS
11
+ and then sending keys when setting values to text inputs in order to more closely simulate user behavior
12
+
13
+ ### Fixed
14
+
15
+ * Relative paths passed to `attach_file` will be assumed to be relative to the current working directory when using the
16
+ Selenium driver
17
+
1
18
  # Version 3.23.0
2
19
  Release date: 2019-06-10
3
20
 
data/README.md CHANGED
@@ -7,8 +7,7 @@
7
7
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jnicklas/capybara?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=capybara&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=capybara&package-manager=bundler&version-scheme=semver)
9
9
 
10
- **Note** You are viewing the README for the 3.23.x version of Capybara.
11
-
10
+ **Note** You are viewing the README for the 3.24.x version of Capybara.
12
11
 
13
12
  Capybara helps you test web applications by simulating how a real user would
14
13
  interact with your app. It is agnostic about the driver running your tests and
@@ -6,7 +6,7 @@ require 'capybara/selenium/patches/logs'
6
6
  module Capybara::Selenium::Driver::ChromeDriver
7
7
  def self.extended(base)
8
8
  bridge = base.send(:bridge)
9
- bridge.extend Capybara::Selenium::ChromeLogs unless bridge.respond_to?(:available_log_types)
9
+ bridge.extend Capybara::Selenium::ChromeLogs unless bridge.respond_to?(:log)
10
10
  end
11
11
 
12
12
  def fullscreen_window(handle)
@@ -90,9 +90,13 @@ private
90
90
  end
91
91
 
92
92
  def execute_cdp(cmd, params = {})
93
- args = { cmd: cmd, params: params }
94
- result = bridge.http.call(:post, "session/#{bridge.session_id}/goog/cdp/execute", args)
95
- result['value']
93
+ if browser.respond_to? :execute_cdp
94
+ browser.execute_cdp(cmd, params)
95
+ else
96
+ args = { cmd: cmd, params: params }
97
+ result = bridge.http.call(:post, "session/#{bridge.session_id}/goog/cdp/execute", args)
98
+ result['value']
99
+ end
96
100
  end
97
101
 
98
102
  def build_node(native_node, initial_cache = {})
@@ -224,10 +224,7 @@ private
224
224
  elsif clear.is_a? Array
225
225
  send_keys(*clear, value)
226
226
  else
227
- # Clear field by JavaScript assignment of the value property.
228
- # Script can change a readonly element which user input cannot, so
229
- # don't execute if readonly.
230
- driver.execute_script "if (!arguments[0].readOnly){ arguments[0].value = '' }", self unless clear == :none
227
+ driver.execute_script 'arguments[0].select()', self unless clear == :none
231
228
  send_keys(value)
232
229
  end
233
230
  end
@@ -303,7 +300,7 @@ private
303
300
 
304
301
  def set_file(value) # rubocop:disable Naming/AccessorMethodName
305
302
  path_names = value.to_s.empty? ? [] : value
306
- native.send_keys(Array(path_names).join("\n"))
303
+ native.send_keys(Array(path_names).map(&File.method(:expand_path)).join("\n"))
307
304
  end
308
305
 
309
306
  def set_content_editable(value) # rubocop:disable Naming/AccessorMethodName
@@ -34,6 +34,8 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
34
34
 
35
35
  def click(*)
36
36
  super
37
+ rescue ::Selenium::WebDriver::Error::ElementClickInterceptedError
38
+ raise
37
39
  rescue ::Selenium::WebDriver::Error::WebDriverError => e
38
40
  # chromedriver 74 (at least on mac) raises the wrong error for this
39
41
  raise ::Selenium::WebDriver::Error::ElementClickInterceptedError, e.message if e.message.match?(/element click intercepted/)
@@ -16,7 +16,9 @@ class Capybara::Selenium::SafariNode < Capybara::Selenium::Node
16
16
  return find_css('th:first-child,td:first-child')[0].click(keys, options)
17
17
  end
18
18
  raise
19
- rescue ::Selenium::WebDriver::Error::WebDriverError
19
+ rescue ::Selenium::WebDriver::Error::WebDriverError => e
20
+ raise unless e.instance_of? ::Selenium::WebDriver::Error::WebDriverError
21
+
20
22
  # Safari doesn't return a specific error here - assume it's an ElementNotInteractableError
21
23
  raise ::Selenium::WebDriver::Error::ElementNotInteractableError,
22
24
  'Non distinct error raised in #click, translated to ElementNotInteractableError for retry'
@@ -4,16 +4,43 @@ module Capybara
4
4
  module Selenium
5
5
  module ChromeLogs
6
6
  LOG_MSG = <<~MSG
7
- Chromedriver 75+ defaults to W3C mode. The W3C webdriver spec does not define methods for accessing \
8
- logs or log types. If you need to access the logs, in the short term, you can configure you driver to not use the W3C mode. \
9
- It is unknown how long non-W3C mode will be supported by chromedriver (it won't be supported by selenium-webdriver 4+) \
10
- so you may need to consider other solutions in the near future.
7
+ Chromedriver 75+ defaults to W3C mode. Please upgrade to chromedriver >= \
8
+ 75.0.3770.90 if you need to access logs while in W3C compliant mode.
11
9
  MSG
12
10
 
13
- def method_missing(meth, *) # rubocop:disable Style/MissingRespondToMissing
14
- raise NotImplementedError, LOG_MSG if %i[available_log_types log].include? meth
11
+ COMMANDS = {
12
+ get_available_log_types: [:get, 'session/:session_id/se/log/types'],
13
+ get_log: [:post, 'session/:session_id/se/log'],
14
+ get_log_legacy: [:post, 'session/:session_id/log']
15
+ }.freeze
15
16
 
16
- super
17
+ def commands(command)
18
+ COMMANDS[command] || super
19
+ end
20
+
21
+ def available_log_types
22
+ types = execute :get_available_log_types
23
+ Array(types).map(&:to_sym)
24
+ rescue ::Selenium::WebDriver::Error::UnknownCommandError
25
+ raise NotImplementedError, LOG_MSG
26
+ end
27
+
28
+ def log(type)
29
+ data = begin
30
+ execute :get_log, {}, type: type.to_s
31
+ rescue ::Selenium::WebDriver::Error::UnknownCommandError
32
+ execute :get_log_legacy, {}, type: type.to_s
33
+ end
34
+
35
+ Array(data).map do |l|
36
+ begin
37
+ ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
38
+ rescue KeyError
39
+ next
40
+ end
41
+ end
42
+ rescue ::Selenium::WebDriver::Error::UnknownCommandError
43
+ raise NotImplementedError, LOG_MSG
17
44
  end
18
45
  end
19
46
  end
@@ -13,17 +13,6 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
13
13
  FileUtils.rm_rf alternative_path
14
14
  end
15
15
 
16
- around do |example|
17
- # Workaround RSpec Issue - https://github.com/rspec/rspec-support/issues/374
18
- if respond_to?(:without_partial_double_verification)
19
- without_partial_double_verification do
20
- example.run
21
- end
22
- else
23
- example.run
24
- end
25
- end
26
-
27
16
  it 'generates sensible filename' do
28
17
  allow(@session.driver).to receive(:save_screenshot)
29
18
 
@@ -212,6 +212,10 @@ class TestApp < Sinatra::Base
212
212
  end
213
213
  end
214
214
 
215
+ get '/apple-touch-icon-precomposed.png' do
216
+ halt(404)
217
+ end
218
+
215
219
  class << self
216
220
  attr_accessor :form_post_count
217
221
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Capybara
4
- VERSION = '3.23.0'
4
+ VERSION = '3.24.0'
5
5
  end
@@ -125,16 +125,17 @@ RSpec.describe 'Capybara::Session with chrome' do
125
125
  describe 'log access' do
126
126
  before { skip 'Only makes sense in W3C mode' if ENV['W3C'] == 'false' }
127
127
 
128
- it 'errors when getting log types' do
128
+ it 'does not error getting log types' do
129
+ skip if Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0]) < Gem::Version.new('75.0.3770.90')
129
130
  expect do
130
131
  session.driver.browser.manage.logs.available_types
131
- end.to raise_error(NotImplementedError, /Chromedriver 75\+ defaults to W3C mode/)
132
+ end.not_to raise_error
132
133
  end
133
134
 
134
- it 'errors when getting logs' do
135
+ it 'does not error when getting logs' do
135
136
  expect do
136
137
  session.driver.browser.manage.logs.get(:browser)
137
- end.to raise_error(NotImplementedError, /Chromedriver 75\+ defaults to W3C mode/)
138
+ end.not_to raise_error
138
139
  end
139
140
  end
140
141
  end
@@ -80,4 +80,21 @@ RSpec.describe 'Capybara::Session with remote Chrome' do
80
80
  it 'is considered to be chrome' do
81
81
  expect(session.driver.browser.browser).to eq :chrome
82
82
  end
83
+
84
+ describe 'log access' do
85
+ before { skip 'Only makes sense in W3C mode' if ENV['W3C'] == 'false' }
86
+
87
+ it 'does not error when getting log types' do
88
+ skip if Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0]) < Gem::Version.new('75.0.3770.90')
89
+ expect do
90
+ session.driver.browser.manage.logs.available_types
91
+ end.not_to raise_error
92
+ end
93
+
94
+ it 'does not error when getting logs' do
95
+ expect do
96
+ session.driver.browser.manage.logs.get(:browser)
97
+ end.not_to raise_error
98
+ end
99
+ end
83
100
  end
@@ -321,6 +321,13 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
321
321
  session.click_button('Upload Multiple')
322
322
  expect(session.body).to include('5 | ') # number of files
323
323
  end
324
+
325
+ it 'can attach a relative file' do
326
+ session.visit('/form')
327
+ session.attach_file('Single Document', 'spec/fixtures/capybara.csv')
328
+ session.click_button('Upload Single')
329
+ expect(session.body).to include('Content-type: text/csv')
330
+ end
324
331
  end
325
332
 
326
333
  context 'Windows' do
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rspec/expectations'
4
- require 'webdrivers' if ENV['CI']
4
+ require 'webdrivers' if ENV['CI'] || ENV['WEBDRIVERS']
5
5
  require 'selenium_statistics'
6
6
  if ENV['TRAVIS']
7
7
  require 'coveralls'
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.23.0
4
+ version: 3.24.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: 2019-06-10 00:00:00.000000000 Z
13
+ date: 2019-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable