Ruby on rails Rails 6,Docker,系统测试-期望找到文本“;“家”;在"E;”页面未呈现
我刚刚启动了一个新的Rails 6项目,该项目在开发中使用了Docker。这是我第一次对接Rails项目,所以这可能是一个简单的解决方案,我似乎可以理解 我正在使用minitest和capybara运行systemtests,但出现以下错误:Ruby on rails Rails 6,Docker,系统测试-期望找到文本“;“家”;在"E;”页面未呈现,ruby-on-rails,docker,selenium,testing,minitest,Ruby On Rails,Docker,Selenium,Testing,Minitest,我刚刚启动了一个新的Rails 6项目,该项目在开发中使用了Docker。这是我第一次对接Rails项目,所以这可能是一个简单的解决方案,我似乎可以理解 我正在使用minitest和capybara运行systemtests,但出现以下错误: FAIL["test_visiting_the_index", #<Minitest::Reporters::Suite:0x000056464fc2f9c0 @name="HomesTest">, 3.
FAIL["test_visiting_the_index", #<Minitest::Reporters::Suite:0x000056464fc2f9c0 @name="HomesTest">, 3.103664200010826]
test_visiting_the_index#HomesTest (3.10s)
expected to find text "Home" in ""
test/system/homes_test.rb:7:in `block in <class:HomesTest>'
docker compose.yml
version: '3.2'
services:
...
app:
depends_on:
- db
- chrome
build: .
command: foreman start -f Procfile.dev -p 3000
ports:
- "3000:3000"
- "35729:35729"
- "3434:3434"
environment:
- DATABASE_HOST=db
- BUNDLE_PATH=/bundle/vendor
- HUB_URL=http://chrome:4444/wd/hub
volumes:
- .:/app
- type: tmpfs
target: /app/tmp/pids/
- bundle_path:/bundle
...
chrome:
image: selenium/standalone-chrome-debug
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
volumes:
redis:
postgres:
bundle_path:
应用程序\系统\测试\案例.rb
require "test_helper"
Capybara.register_driver :chrome_headless do |app|
chrome_capabilities = ::Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { 'args': %w[no-sandbox headless disable-gpu window-size=1400,1400] })
if ENV['HUB_URL']
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: ENV['HUB_URL'],
desired_capabilities: chrome_capabilities)
else
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: chrome_capabilities)
end
end
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
parallelize(workers: 1)
driven_by :chrome_headless
end
require "application_system_test_case"
class HomesTest < ApplicationSystemTestCase
test "visiting the index" do
visit root_path
assert_text "Home"
end
end
需要“测试助手”
Capybara.register_驱动程序:chrome_无头do|应用程序|
chrome_功能=::Selenium::WebDriver::Remote::capabilities.chrome('goog:chromeOptions'=>{'args':%w[无沙盒无头禁用gpu窗口大小=14001400]})
if ENV['HUB_URL']
水豚::硒::驱动程序。新(应用程序,
浏览器::远程,
url:ENV['HUB_url'],
所需的_功能:chrome_功能)
其他的
水豚::硒::驱动程序。新(应用程序,
浏览器::chrome,
所需的_功能:chrome_功能)
结束
结束
类ApplicationSystemTestCase
homes\u test.rb
require "test_helper"
Capybara.register_driver :chrome_headless do |app|
chrome_capabilities = ::Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { 'args': %w[no-sandbox headless disable-gpu window-size=1400,1400] })
if ENV['HUB_URL']
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: ENV['HUB_URL'],
desired_capabilities: chrome_capabilities)
else
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: chrome_capabilities)
end
end
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
parallelize(workers: 1)
driven_by :chrome_headless
end
require "application_system_test_case"
class HomesTest < ApplicationSystemTestCase
test "visiting the index" do
visit root_path
assert_text "Home"
end
end
需要“应用程序\系统\测试用例”
类HomesTest
home index.html.erb(根路径)
主页
尝试检查response.body
以查看rails真正呈现的内容。当我
在索引视图中时,它返回“”
。与错误相同。这是什么意思?我可以通过浏览器访问该页面,并进行渲染。我已经公开了github项目。它是新创建的,只包含一个主控制器和用户控制器。我尝试过在docker容器外运行测试,就像标准的dev.env一样。而且效果很好。这告诉我,问题不在于gem设置或capybara/minitest。这一定与docker的设置有关?
<h1>Home</h1>