Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rake_tasks/selenium_rake/checks.rb
1864 views
1
# frozen_string_literal: true
2
3
require 'rbconfig'
4
5
module SeleniumRake
6
class Checks
7
class << self
8
PRESENT_CACHE = {}
9
10
def windows?
11
(RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw32/) != nil
12
end
13
14
def mac?
15
(RbConfig::CONFIG['host_os'] =~ /darwin|mac os/) != nil
16
end
17
18
def linux?
19
!windows? && !mac?
20
end
21
22
def dir_separator
23
File::ALT_SEPARATOR || File::SEPARATOR
24
end
25
26
def path_for(path)
27
windows? ? path.gsub('/', dir_separator) : path
28
end
29
30
def classpath_separator?
31
if cygwin?
32
';'
33
else
34
File::PATH_SEPARATOR
35
end
36
end
37
38
def chrome?
39
present?('chromedriver') || present?('chromedriver.exe')
40
end
41
42
def edge?
43
present?('msedgedriver') || present?('msedgedriver.exe')
44
end
45
46
def opera?
47
present?('opera') || present?('Opera')
48
end
49
50
def python?
51
present?('python') || present?('python.exe')
52
end
53
54
private
55
56
def cygwin?
57
RUBY_PLATFORM.downcase.include?('cygwin')
58
end
59
60
def present?(arg)
61
return PRESENT_CACHE[arg] if PRESENT_CACHE.key?(arg)
62
return PRESENT_CACHE[arg] = true if exist_on_non_mac?(arg)
63
return PRESENT_CACHE[arg] = exist_on_mac?(arg) if mac?
64
PRESENT_CACHE[arg] = false
65
end
66
67
def exist_on_non_mac?(arg)
68
prefixes.any? do |prefix|
69
File.exist?("#{prefix}#{File::SEPARATOR}#{arg}")
70
end
71
end
72
73
def exist_on_mac?(arg)
74
File.exist?("/Applications/#{arg}.app")
75
end
76
77
def prefixes
78
ENV['PATH'].split(File::PATH_SEPARATOR)
79
end
80
end
81
end
82
end
83
84