2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2014-08-14 14:09:21 -04:00
|
|
|
require 'rspec/expectations'
|
2019-06-10 15:36:01 -04:00
|
|
|
require 'webdrivers' if ENV['CI'] || ENV['WEBDRIVERS']
|
2019-01-03 16:00:38 -05:00
|
|
|
require 'selenium_statistics'
|
2019-04-27 13:00:00 -04:00
|
|
|
if ENV['TRAVIS']
|
2019-04-25 03:39:37 -04:00
|
|
|
require 'coveralls'
|
|
|
|
Coveralls.wear! do
|
|
|
|
add_filter '/lib/capybara/driver/'
|
|
|
|
add_filter '/lib/capybara/registrations/'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
require 'capybara/spec/spec_helper'
|
2012-11-28 15:02:21 -05:00
|
|
|
|
2018-08-24 14:32:55 -04:00
|
|
|
module Capybara
|
|
|
|
module SpecHelper
|
2018-11-18 16:27:00 -05:00
|
|
|
def firefox?(session)
|
2018-08-24 14:32:55 -04:00
|
|
|
browser_name(session) == :firefox &&
|
2019-04-18 03:28:05 -04:00
|
|
|
((defined?(::Selenium::WebDriver::VERSION) && (::Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
|
|
|
session.driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities))
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
|
2018-11-18 16:27:00 -05:00
|
|
|
def firefox_lt?(version, session)
|
|
|
|
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
|
2018-11-18 16:27:00 -05:00
|
|
|
def firefox_gte?(version, session)
|
|
|
|
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def chrome?(session)
|
|
|
|
browser_name(session) == :chrome
|
|
|
|
end
|
|
|
|
|
2019-06-01 21:17:59 -04:00
|
|
|
def chrome_version(session)
|
|
|
|
(session.driver.browser.capabilities[:browser_version] ||
|
|
|
|
session.driver.browser.capabilities[:version]).to_f
|
|
|
|
end
|
|
|
|
|
2018-08-24 14:32:55 -04:00
|
|
|
def chrome_lt?(version, session)
|
2019-06-01 21:17:59 -04:00
|
|
|
chrome?(session) && (chrome_version(session) < version)
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def chrome_gte?(version, session)
|
2019-06-04 15:21:02 -04:00
|
|
|
chrome?(session) && (chrome_version(session) >= version)
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def edge?(session)
|
2019-06-04 17:35:44 -04:00
|
|
|
browser_name(session).match?(/^edge/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def legacy_edge?(session)
|
2018-08-24 14:32:55 -04:00
|
|
|
browser_name(session) == :edge
|
|
|
|
end
|
|
|
|
|
2019-06-01 21:17:59 -04:00
|
|
|
def edge_lt?(version, session)
|
|
|
|
edge?(session) && (chrome_version(session) < version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edge_gte?(version, session)
|
|
|
|
edge?(session) && (chrome_version(session) >= version)
|
|
|
|
end
|
|
|
|
|
2018-08-24 14:32:55 -04:00
|
|
|
def ie?(session)
|
|
|
|
%i[internet_explorer ie].include?(browser_name(session))
|
|
|
|
end
|
|
|
|
|
2019-03-13 21:21:53 -04:00
|
|
|
def safari?(session)
|
|
|
|
%i[safari Safari Safari_Technology_Preview].include?(browser_name(session))
|
|
|
|
end
|
|
|
|
|
2018-08-24 14:32:55 -04:00
|
|
|
def browser_name(session)
|
|
|
|
session.driver.browser.browser if session.respond_to?(:driver)
|
|
|
|
end
|
2018-09-24 12:41:47 -04:00
|
|
|
|
|
|
|
def remote?(session)
|
|
|
|
session.driver.browser.is_a? ::Selenium::WebDriver::Remote::Driver
|
|
|
|
end
|
2019-04-19 15:22:17 -04:00
|
|
|
|
|
|
|
def self.log_selenium_driver_version(mod)
|
|
|
|
mod = mod::Service if ::Selenium::WebDriver::Service.respond_to? :driver_path
|
|
|
|
path = mod.driver_path
|
|
|
|
path = path.call if path.respond_to? :call
|
2019-04-30 15:00:15 -04:00
|
|
|
$stdout.puts `#{path.gsub(' ', '\ ')} --version`
|
2019-04-19 15:22:17 -04:00
|
|
|
end
|
2018-08-24 14:32:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-28 15:02:21 -05:00
|
|
|
RSpec.configure do |config|
|
|
|
|
Capybara::SpecHelper.configure(config)
|
2019-04-18 19:18:04 -04:00
|
|
|
config.expect_with :rspec do |expectations|
|
|
|
|
expectations.syntax = :expect
|
|
|
|
end
|
2019-04-19 18:20:10 -04:00
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
2018-12-20 15:37:14 -05:00
|
|
|
config.filter_run_including focus_: true unless ENV['CI']
|
2017-01-13 14:59:38 -05:00
|
|
|
config.run_all_when_everything_filtered = true
|
2019-01-03 16:00:38 -05:00
|
|
|
config.after(:suite) { SeleniumStatistics.print_results }
|
2012-11-28 15:02:21 -05:00
|
|
|
end
|