我在从WSL上运行的Ubuntu 18.04内的全新Rails 5.2应用程序上运行系统测试时遇到问题。
我已使用chromium-browser
在Ubuntu上安装了sudo apt-get install chromium-browser
。
test / application_system_test_case.rb:
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
test / system / authentication_test.rb:
class AuthenticationTest < ApplicationSystemTestCase
test 'prompting for credentials' do
visit '/'
assert new_user_session_path, current_path
end
end
运行rails test:system
时发生以下崩溃:
2019-07-03 13:07:58 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
Started with run options --seed 62037
AuthenticationTest
test_prompting_for_credentials ERROR (1.44s)
Selenium::WebDriver::Error::UnknownError: Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
test/system/authentication_test.rb:6:in `block in <class:AuthenticationTest>'
如果通过将以下内容添加到基本系统测试类中来更改Chrome路径以指向Windows Chrome安装:
Selenium::WebDriver::Chrome.path = '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
当我运行rails test:system
时,它将打开两个控制台窗口和两个Chrome窗口。
Chrome抛出错误“无法从C:\ tmp.com.google。\ Internal加载扩展名。清单文件丢失或不可读”。
控制台窗口都有以下错误:
[14148:9072:0703/131126.030:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: PRAGMA auto_vacuum
[14148:9072:0703/131126.034:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: PRAGMA journal_mode=TRUNCATE
[14148:9072:0703/131126.040:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: SELECT 1 FROM sqlite_master WHERE type=? AND name=?
[14148:9072:0703/131126.044:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: SELECT 1 FROM sqlite_master WHERE type=? AND name=?
[14148:9072:0703/131126.048:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR)
[14148:6880:0703/131126.217:ERROR:backend_impl.cc(1437)] Unable to map Index file
[14148:10312:0703/131126.230:ERROR:cache_util_win.cc(21)] Unable to move the cache: The system cannot find the file specified. (0x2)
[14148:10312:0703/131126.230:ERROR:cache_util.cc(141)] Unable to move cache folder \\wsl$\Ubuntu-18.04\tmp\.com.google.Chrome.HgtI05\Default\Cache to \\wsl$\Ubuntu-18.04\tmp\.com.google.Chrome.HgtI05\Default\old_Cache_000
[14148:10312:0703/131126.230:ERROR:disk_cache.cc(178)] Unable to create cache
[14148:9072:0703/131126.233:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: PRAGMA auto_vacuum
[14148:9072:0703/131126.237:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: PRAGMA journal_mode=TRUNCATE
[14148:9072:0703/131126.241:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: SELECT 1 FROM sqlite_master WHERE type=? AND name=?
[14148:9072:0703/131126.245:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: SELECT 1 FROM sqlite_master WHERE type=? AND name=?
[14148:9072:0703/131126.249:ERROR:database.cc(1601)] Cookie sqlite error 5, errno 1: database is locked, sql: CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR)
并且测试因以下原因而崩溃:
AuthenticationTest
test_prompting_for_credentials ERROR (62.19s)
Selenium::WebDriver::Error::SessionNotCreatedError: Selenium::WebDriver::Error::SessionNotCreatedError: session not created
from tab crashed
(Session info: chrome=75.0.3770.100)
test/system/authentication_test.rb:6:in `block in <class:AuthenticationTest>'
答案 0 :(得分:0)
在这个 post 的帮助下,我能够让它工作。您无需安装 chromium-browser
或任何其他 Ubuntu 软件包。如果这对其他人有帮助,这就是我所做的:
chromedriver.exe
重命名为 chromedriver
。通过从 bash 控制台运行 chromedriver -v
,确保 WSL 可以访问它。ApplicationSystemTestCase
中设置以下选项:require 'test_helper'
CHROMEDRIVER_URL = 'http://localhost:9515/'
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
Capybara.register_driver :selenium_remote_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--start-maximized')
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: CHROMEDRIVER_URL,
desired_capabilities: :chrome,
options: options
)
end
Capybara.configure do |config|
# Match what's set for URL options in test.rb so we
# can test mailers that contain links.
config.server_host = 'localhost'
config.server_port = '3000'
end
driven_by :selenium_remote_chrome
end
chromedriver
来启动 chromedriver 服务器。rails test:system
运行系统测试。