selenium_chrome_helper 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/selenium_chrome_helper/railtie.rb +37 -28
- data/lib/selenium_chrome_helper/version.rb +1 -1
- data/lib/selenium_chrome_helper.rb +3 -5
- data/lib/tasks/install.rake +12 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a3dc606169a2ead1a95947305d962a396049f2b9efccfbde7159acf34a7c3e
|
4
|
+
data.tar.gz: 9f9e3a441cd650e01dceb5d47bbdaa7e3e8360d4f2fc109532ffe5ab580e35ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d7f88532fa87a1914bb543c5cbf4d54d739700ed7e25d2b0bbf3df5984a6851d2486b319c109adc1e0be4c17b05e8e0ccd7a2254ebff3c4a00fdc4ffa1f2211
|
7
|
+
data.tar.gz: c15546c7264ddb8abe4bc278b73a54ed1db0717a31b14580b0638d43f4df862dda5fd0869e6ef75f80a79821d30b0fcb1a95e2fb0152b09edcf16dfdd10f4c76
|
@@ -10,30 +10,21 @@ module SeleniumChromeHelper
|
|
10
10
|
# This Railtie configures Capybara to use a specific version of Google Chrome for testing.
|
11
11
|
# It registers two drivers: one for headless testing and one for non-headless testing.
|
12
12
|
class Railtie < Rails::Railtie
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
chrome_path = determine_chrome_path(base_path, platform)
|
17
|
-
driver_path = base_path.join("chromedriver-#{platform}", 'chromedriver').to_s
|
18
|
-
|
19
|
-
Capybara.register_driver :chrome_for_testing do |app|
|
20
|
-
Selenium::WebDriver::Chrome::Service.driver_path = driver_path
|
21
|
-
|
22
|
-
options = configure_browser_options(chrome_path)
|
23
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
24
|
-
end
|
25
|
-
|
26
|
-
Capybara.register_driver :chrome_for_testing_gui do |app|
|
27
|
-
Selenium::WebDriver::Chrome::Service.driver_path = driver_path
|
13
|
+
rake_tasks do
|
14
|
+
load File.expand_path('../tasks/install.rake', __dir__)
|
15
|
+
end
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
initializer 'selenium_chrome_helper.configure_capybara' do
|
18
|
+
SeleniumChromeHelper::Railtie.register_driver(:chrome_for_testing, headless: true)
|
19
|
+
SeleniumChromeHelper::Railtie.register_driver(:chrome_for_testing_gui, headless: false)
|
32
20
|
end
|
33
21
|
|
34
|
-
|
22
|
+
def self.base_path
|
23
|
+
custom = ENV['CHROME_FOR_TESTING_PATH']
|
24
|
+
Pathname.new(custom || Rails.root.join('.chrome-for-testing', CHROME_VERSION))
|
25
|
+
end
|
35
26
|
|
36
|
-
def
|
27
|
+
def self.platform
|
37
28
|
case RUBY_PLATFORM
|
38
29
|
when /darwin/
|
39
30
|
`uname -m`.strip == 'arm64' ? 'mac-arm64' : 'mac-x64'
|
@@ -44,16 +35,26 @@ module SeleniumChromeHelper
|
|
44
35
|
end
|
45
36
|
end
|
46
37
|
|
47
|
-
def
|
48
|
-
if platform.start_with?('mac')
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
38
|
+
def self.chrome_path
|
39
|
+
path = if platform.start_with?('mac')
|
40
|
+
base_path.join("chrome-#{platform}", 'Google Chrome for Testing.app', 'Contents',
|
41
|
+
'MacOS', 'Google Chrome for Testing')
|
42
|
+
else
|
43
|
+
base_path.join("chrome-#{platform}", 'chrome')
|
44
|
+
end
|
45
|
+
warn "⚠️ Chrome binary not found at #{path}. Did you run `rake chrome:install`?" unless File.exist?(path)
|
46
|
+
|
47
|
+
path.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.driver_path
|
51
|
+
path = base_path.join("chromedriver-#{platform}", 'chromedriver')
|
52
|
+
warn "⚠️ Chromedriver not found at #{path}. Did you run `rake chrome:install`?" unless File.exist?(path)
|
53
|
+
|
54
|
+
path.to_s
|
54
55
|
end
|
55
56
|
|
56
|
-
def configure_browser_options(
|
57
|
+
def self.configure_browser_options(headless: true)
|
57
58
|
options = Selenium::WebDriver::Chrome::Options.new
|
58
59
|
options.binary = chrome_path
|
59
60
|
options.add_argument('--headless=new') if headless
|
@@ -62,5 +63,13 @@ module SeleniumChromeHelper
|
|
62
63
|
options.add_argument('--window-size=1400,1400')
|
63
64
|
options
|
64
65
|
end
|
66
|
+
|
67
|
+
def self.register_driver(name, headless:)
|
68
|
+
Capybara.register_driver name do |app|
|
69
|
+
Selenium::WebDriver::Chrome::Service.driver_path = driver_path
|
70
|
+
options = configure_browser_options(headless: headless)
|
71
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
72
|
+
end
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
if defined?(
|
5
|
-
load File.expand_path("tasks/install.rake", __dir__)
|
6
|
-
end
|
3
|
+
require 'selenium_chrome_helper/version'
|
4
|
+
require 'selenium_chrome_helper/railtie' if defined?(Rails::Railtie)
|
data/lib/tasks/install.rake
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'open-uri'
|
5
5
|
require 'json'
|
6
|
-
require 'zip'
|
6
|
+
require 'zip'
|
7
7
|
|
8
8
|
# rubocop:disable Metrics/BlockLength, Security/Open
|
9
9
|
namespace :chrome do
|
@@ -11,7 +11,7 @@ namespace :chrome do
|
|
11
11
|
task :install, [:version] do |_, args|
|
12
12
|
version = args[:version] || '134.0.6998.165'
|
13
13
|
api_url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'
|
14
|
-
install_base = File.expand_path("chrome-for-testing
|
14
|
+
install_base = File.expand_path(".chrome-for-testing/#{version}", Dir.pwd)
|
15
15
|
|
16
16
|
platform = case RUBY_PLATFORM
|
17
17
|
when /darwin/
|
@@ -19,35 +19,35 @@ namespace :chrome do
|
|
19
19
|
when /linux/
|
20
20
|
'linux64'
|
21
21
|
else
|
22
|
-
raise "Unsupported platform:
|
22
|
+
raise "Unsupported platform: #{RUBY_PLATFORM}"
|
23
23
|
end
|
24
24
|
|
25
|
-
puts "➡️ Platform:
|
26
|
-
puts "📡 Fetching metadata for Chrome version
|
25
|
+
puts "➡️ Platform: #{platform}"
|
26
|
+
puts "📡 Fetching metadata for Chrome version #{version}..."
|
27
27
|
|
28
28
|
json = URI.open(api_url).read
|
29
29
|
data = JSON.parse(json)
|
30
30
|
|
31
31
|
version_info = data['versions'].find { |v| v['version'] == version }
|
32
32
|
|
33
|
-
abort "❌ Version
|
33
|
+
abort "❌ Version #{version} not found in known-good list." unless version_info
|
34
34
|
|
35
35
|
chrome_url = version_info.dig('downloads', 'chrome')&.find { |d| d['platform'] == platform }&.dig('url')
|
36
36
|
driver_url = version_info.dig('downloads', 'chromedriver')&.find { |d| d['platform'] == platform }&.dig('url')
|
37
37
|
|
38
38
|
unless chrome_url && driver_url
|
39
|
-
abort "❌ No matching downloads found for platform
|
39
|
+
abort "❌ No matching downloads found for platform #{platform} and version #{version}"
|
40
40
|
end
|
41
41
|
|
42
|
-
puts "⬇️ Chrome URL:
|
43
|
-
puts "⬇️ Chromedriver URL:
|
42
|
+
puts "⬇️ Chrome URL: #{chrome_url}"
|
43
|
+
puts "⬇️ Chromedriver URL: #{driver_url}"
|
44
44
|
|
45
45
|
FileUtils.mkdir_p(install_base)
|
46
46
|
|
47
47
|
download_and_unzip(chrome_url, File.join(install_base, 'chrome.zip'), install_base)
|
48
48
|
download_and_unzip(driver_url, File.join(install_base, 'chromedriver.zip'), install_base)
|
49
49
|
|
50
|
-
puts "✅ Chrome and Chromedriver installed to
|
50
|
+
puts "✅ Chrome and Chromedriver installed to #{install_base}"
|
51
51
|
end
|
52
52
|
|
53
53
|
def download_and_unzip(url, zip_path, extract_to)
|
@@ -66,6 +66,8 @@ namespace :chrome do
|
|
66
66
|
def unzip(zip_path, extract_to)
|
67
67
|
Zip::File.open(zip_path) do |zip_file|
|
68
68
|
zip_file.each do |entry|
|
69
|
+
next if entry.symlink? # silently skip symlinks
|
70
|
+
|
69
71
|
entry_path = File.join(extract_to, entry.name)
|
70
72
|
FileUtils.mkdir_p(File.dirname(entry_path))
|
71
73
|
zip_file.extract(entry, entry_path) unless File.exist?(entry_path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium_chrome_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Robaina
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rubyzip
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '2.0'
|
41
41
|
description: Adds a rake task (`chrome:install`) to easily fetch a pinned version
|
42
42
|
of Chrome and Chromedriver locally or in CI.
|
43
43
|
email:
|