Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility with selenium-webdriver 4.x #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
3.1.0
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ language: ruby
addons:
chrome: stable
rvm:
- 2.6.5
before_install: gem install bundler -v 1.16.0
- 2.6.9
- 2.7.5
- 3.0.3
- 3.1.0
before_install:
gem update --system 3.3.5
gem install bundler -v 2.3.5
94 changes: 50 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,82 @@ PATH
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
capybara (3.31.0)
capybara (3.36.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.2)
childprocess (4.1.0)
coderay (1.1.3)
colorize (0.8.1)
diff-lcs (1.3)
ffi (1.12.2)
gem-release (2.0.1)
method_source (0.9.0)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (4.0.3)
rack (2.0.8)
diff-lcs (1.5.0)
gem-release (2.2.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.7.1)
nokogiri (1.13.1)
mini_portile2 (~> 2.7.0)
racc (~> 1.4)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.1)
regexp_parser (1.7.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rake (13.0.6)
regexp_parser (2.2.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubyzip (1.2.1)
selenium-webdriver (3.9.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
stub_server (0.2.1)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
rubyzip (2.3.2)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
stub_server (0.6.0)
rack
webdrivers (4.1.2)
webrick
webdrivers (5.0.0)
nokogiri (~> 1.6)
rubyzip (~> 1.0)
selenium-webdriver (>= 3.0, < 4.0)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
webrick (1.7.0)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
bundler (~> 2.3)
capybara-chromedriver-logger!
gem-release
pry
rake (~> 13.0)
rspec (~> 3.0)
selenium-webdriver
selenium-webdriver (~> 4.1)
stub_server
webdrivers (~> 4.0)
webdrivers (~> 5.0)

BUNDLED WITH
1.17.3
2.3.5
6 changes: 3 additions & 3 deletions capybara-chromedriver-logger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ Gem::Specification.new do |spec|
spec.add_dependency "capybara"
spec.add_dependency "colorize"

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "bundler", "~> 2.3"
spec.add_development_dependency "gem-release"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "selenium-webdriver"
spec.add_development_dependency "selenium-webdriver", "~> 4.1"
spec.add_development_dependency "stub_server"
spec.add_development_dependency 'webdrivers', '~> 4.0'
spec.add_development_dependency 'webdrivers', '~> 5.0'
end
39 changes: 38 additions & 1 deletion lib/capybara/chromedriver/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,35 @@ module Chromedriver
module Logger
extend self

def build_capabilities(loggingPrefs: { browser: 'ALL' }, **options)
# == compatibility with selenium-webdriver 4.x
#
# Selenium::WebDriver's API changed significantly between 3.x and 4.x.
#
# This method delegates to build_capabilities_3 or build_capabilities_4.
def build_capabilities(logging_prefs: { browser: 'ALL' }, **options)
# backwards compatibility with camelcase
logging_prefs = options.delete(:loggingPrefs) || logging_prefs

if using_selenium_webdriver_4_or_higher?
# is there a better way to detect Selenium::WebDriver compatibility?
build_capabilities_4(logging_prefs: logging_prefs, **options)
else
build_capabilities_3(loggingPrefs: logging_prefs, **options)
end
end

# For selenium-webdriver >= 4.0. Capabilities will be created using
# Selenium::WebDriver::Options.chrome and should be passed to
# Capybara::Selenium::Driver.new(..., capabilities: capabilities)
def build_capabilities_4(logging_prefs: { browser: 'ALL' }, **options)
::Selenium::WebDriver::Options.chrome(**options,
logging_prefs: logging_prefs)
end

# For selenium-webdriver < 4.0. Capabilities will be created using
# Selenium::WebDriver::Remote::Capabilities.chrome and should be passed to
# Capybara::Selenium::Driver.new(..., desired_capabilities: capabilities)
def build_capabilities_3(loggingPrefs: { browser: 'ALL' }, **options)
options[:chromeOptions] ||= {}

if options[:chromeOptions][:w3c]
Expand Down Expand Up @@ -60,6 +88,15 @@ def raise_js_errors?
def raise_js_errors=(value)
@raise_js_errors = value
end

# always returns true if Gem::Version isn't defined
def using_selenium_webdriver_4_or_higher?
return true unless defined?(Gem::Version)
return false unless defined?(::Selenium::WebDriver::VERSION)
Gem::Version.new(::Selenium::WebDriver::VERSION) >=
Gem::Version.new("4.0.0.0.a")
end

end
end
end
24 changes: 16 additions & 8 deletions lib/capybara/chromedriver/logger/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def raise_errors_if_needed!
def flush_logs!
browser_logs.each do |log|
message = Message.new(log)

next if should_filter?(message)

errors << message if message.error?

log_destination.puts message.to_s
end
end
Expand All @@ -50,12 +50,20 @@ def browser_logs
end

def logs(type)
Capybara
.current_session
.driver.browser
.manage
.logs
.get(type)
if Logger.using_selenium_webdriver_4_or_higher?
Capybara
.current_session
.driver.browser
.logs
.get(type)
else
Capybara
.current_session
.driver.browser
.manage
.logs
.get(type)
end
end

def should_filter?(message)
Expand Down
16 changes: 8 additions & 8 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
require 'capybara/rspec'

Capybara.register_driver :selenium do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 240

args = %w[
disable-default-apps
disable-extensions
Expand All @@ -21,16 +18,19 @@
]

capabilities = Capybara::Chromedriver::Logger.build_capabilities(
chromeOptions: {
args: args
}
args: args
)

if ENV["VERBOSE_SELENIUM_WEBDRIVER"] == "1"
capabilities.add_argument "--verbose"
Selenium::WebDriver.logger.level = :debug
end

Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities,
http_client: client
capabilities: capabilities,
timeout: 240
)
end

Expand Down