forked from teamcapybara/capybara
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
133 lines (107 loc) · 3.91 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# frozen_string_literal: true
require 'rspec/expectations'
require 'webdrivers' if ENV.fetch('WEBDRIVERS', nil)
require 'selenium_statistics'
if ENV['TRAVIS']
require 'coveralls'
Coveralls.wear! do
add_filter '/lib/capybara/driver/'
add_filter '/lib/capybara/registrations/'
end
end
require 'capybara/spec/spec_helper'
module Capybara
module SpecHelper
def firefox?(session)
browser_name(session) == :firefox &&
((defined?(::Selenium::WebDriver::VERSION) && (Gem::Version.new(::Selenium::WebDriver::VERSION) >= Gem::Version.new('4'))) ||
session.driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities))
end
def firefox_lt?(version, session)
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
end
def firefox_gte?(version, session)
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
end
def geckodriver_version(session)
Gem::Version.new(session.driver.browser.capabilities['moz:geckodriverVersion'])
end
def geckodriver_gte?(version, session)
firefox?(session) && geckodriver_version(session) >= Gem::Version.new(version)
end
def geckodriver_lt?(version, session)
firefox?(session) && geckodriver_version(session) < Gem::Version.new(version)
end
def chrome?(session)
browser_name(session) == :chrome
end
def chrome_version(session)
(session.driver.browser.capabilities[:browser_version] ||
session.driver.browser.capabilities[:version]).to_f
end
def chrome_lt?(version, session)
chrome?(session) && (chrome_version(session) < version)
end
def chrome_gte?(version, session)
chrome?(session) && (chrome_version(session) >= version)
end
def chromedriver_version(session)
Gem::Version.new(session.driver.browser.capabilities['chrome']['chromedriverVersion'].split[0])
end
def chromedriver_gte?(version, session)
chrome?(session) && chromedriver_version(session) >= Gem::Version.new(version)
end
def chromedriver_lt?(version, session)
chrome?(session) && chromedriver_version(session) < Gem::Version.new(version)
end
def selenium?(session)
session.driver.is_a? Capybara::Selenium::Driver
end
def selenium_lt?(version, session)
selenium?(session) &&
Gem::Version.new(::Selenium::WebDriver::VERSION) < Gem::Version.new(version)
end
def edge?(session)
browser_name(session).to_s.start_with?('edge')
end
def legacy_edge?(session)
browser_name(session) == :edge
end
def edge_lt?(version, session)
edge?(session) && (chrome_version(session) < version)
end
def edge_gte?(version, session)
edge?(session) && (chrome_version(session) >= version)
end
def ie?(session)
%i[internet_explorer ie].include?(browser_name(session))
end
def safari?(session)
%i[safari Safari Safari_Technology_Preview].include?(browser_name(session))
end
def browser_name(session)
session.driver.browser.browser if session.respond_to?(:driver)
end
def remote?(session)
session.driver.browser.is_a? ::Selenium::WebDriver::Remote::Driver
end
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
$stdout.puts `#{path.gsub(' ', '\ ')} --version` if path
end
end
end
RSpec.configure do |config|
Capybara::SpecHelper.configure(config)
config.expect_with :rspec do |expectations|
expectations.syntax = :expect
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run_including focus_: true unless ENV['CI']
config.run_all_when_everything_filtered = true
config.after(:suite) { SeleniumStatistics.print_results }
end