Ruby on rails 与rails测试对接的Selenium
我试图在docker中使用Selenium chrome运行rspec测试,但发现了几十个错误。最后,我将capybara连接到远程capybara,但现在出现以下错误: 获得0个失败和2个其他错误:Ruby on rails 与rails测试对接的Selenium,ruby-on-rails,selenium,docker,selenium-webdriver,capybara,Ruby On Rails,Selenium,Docker,Selenium Webdriver,Capybara,我试图在docker中使用Selenium chrome运行rspec测试,但发现了几十个错误。最后,我将capybara连接到远程capybara,但现在出现以下错误: 获得0个失败和2个其他错误: 1.1) Failure/Error: visit new_user_session_path Selenium::WebDriver::Error::WebDriverError: unexpected response, code=404, content-ty
1.1) Failure/Error: visit new_user_session_path
Selenium::WebDriver::Error::WebDriverError:
unexpected response, code=404, content-type="text/html"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Action Controller: Exception caught</title>
这是我的docker-compose.yml:
version: '3'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3001 -b '0.0.0.0'
volumes:
- .:/prs
ports: ['3000:3000', '3001:3001']
# - "3001:3001"
depends_on:
- db
- selenium
extra_hosts:
- "test.prs.com:127.0.0.1"
environment:
- APP_HOST=test.prs.com
links:
- selenium
selenium:
image: selenium/standalone-chrome-debug:3.6.0-bromine
# Debug version enables VNC ability
ports: ['4444:4444', '5900:5900']
# Bind selenium port & VNC port
volumes:
- /dev/shm:/dev/shm
shm_size: 1024m
privileged: true
container_name: selenium
我对所有这些都是新手,因此任何帮助都将不胜感激。从您澄清的评论中,您试图在selenium docker实例中使用selenium驱动的浏览器时在
web
docker实例中运行测试。此外,由于您的测试在本地工作,我假设您使用的是Rails 5.1+,因此特性测试的事务性测试也可以工作。根据这些参数,需要做一些事情才能使一切正常工作
Capybara.run_server = true # You currently have this set to false for some reason
selenium
docker实例访问的界面上运行其应用程序副本。最简单的方法是指定绑定到0.0.0.0
Capybara.server_host = `0.0.0.0`
Capybara.server_port = 3001 # I'm assuming this is what you want, change to another port and make sure it's reachable from `selenium` instance if desired
Capybara.register_driver :remote_browser do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu no-sandbox) }
)
Capybara::Selenium::Driver.new(app,
:browser => :remote,
url: "http://selenium:4444",
desired_capabilities: capabilities
)
end
Capybara.javascript_driver = :remote_browser
# Capybara.default_driver = :remote_browser # only needed if you want all tests to use selenium rather than just JS tagged tests.
Capybara.app_host = "http://web:3001" # a URL that represents the `web` docker instance from the perspective of the `selenium` docker instance
rails s
,因为您希望测试针对一个应用程序实例运行,该应用程序实例由Capybara自己启动#command:bundle exec rails s s-p 3001-b'0.0.0'
。如果您当前在3001上运行的实例用于其他用途,那么您需要一个不同的端口来进行测试
此外,如果您没有运行Rails 5.1+,则需要设置
config.use\u transactional\u fixtures=false
并完全配置数据库\u cleaner
-。如果您使用的是Rails 5.1+,那么您可能可以删除所有数据库清理器内容。从您澄清的评论中,您试图在selenium docker实例中使用selenium驱动的浏览器时在web
docker实例中运行测试。此外,由于您的测试在本地工作,我假设您使用的是Rails 5.1+,因此特性测试的事务性测试也可以工作。根据这些参数,需要做一些事情才能使一切正常工作
Capybara.run_server = true # You currently have this set to false for some reason
selenium
docker实例访问的界面上运行其应用程序副本。最简单的方法是指定绑定到0.0.0.0
Capybara.server_host = `0.0.0.0`
Capybara.server_port = 3001 # I'm assuming this is what you want, change to another port and make sure it's reachable from `selenium` instance if desired
Capybara.register_driver :remote_browser do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu no-sandbox) }
)
Capybara::Selenium::Driver.new(app,
:browser => :remote,
url: "http://selenium:4444",
desired_capabilities: capabilities
)
end
Capybara.javascript_driver = :remote_browser
# Capybara.default_driver = :remote_browser # only needed if you want all tests to use selenium rather than just JS tagged tests.
Capybara.app_host = "http://web:3001" # a URL that represents the `web` docker instance from the perspective of the `selenium` docker instance
rails s
,因为您希望测试针对一个应用程序实例运行,该应用程序实例由Capybara自己启动#command:bundle exec rails s s-p 3001-b'0.0.0'
。如果您当前在3001上运行的实例用于其他用途,那么您需要一个不同的端口来进行测试
此外,如果您没有运行Rails 5.1+,则需要设置
config.use\u transactional\u fixtures=false
并完全配置数据库\u cleaner
-。如果您使用的是Rails 5.1+,那么您可能可以删除所有数据库清理工具。我的问题与Docker、Selenium、Capybara、Chromedriver或任何其他工具完全无关。这些都是骗人的,因为在我的容器上,只有与特性规格相关的测试失败了
事实证明,它们都失败了,因为功能规格是应用程序中唯一查看IP地址的部分
我正在使用
ip\u匿名器
gem,未能为容器设置ip\u HASH\u SECRET
。希望其他人在使用这款gem和Capybara和CI时会发现它很有用。我的问题与Docker、Selenium、Capybara、Chromedriver或任何其他产品完全无关。这些都是骗人的,因为在我的容器上,只有与特性规格相关的测试失败了
事实证明,它们都失败了,因为功能规格是应用程序中唯一查看IP地址的部分
我正在使用
ip\u匿名器
gem,未能为容器设置ip\u HASH\u SECRET
。希望其他使用此gem和Capybara和CI的人会发现这很有用。这些测试在没有Docker的情况下在本地工作吗?这些看起来像rails 404错误,所以我倾向于认为一切都在讨论,但可能存在应用程序错误?请澄清,您正试图做什么。您是否试图在本地主机上运行测试,但在selenium
docker实例中的浏览器上运行测试?或者您正在尝试在web
docker实例中运行测试?通常,Capybara会在运行测试的任何系统上启动正在测试的应用程序本身(这样它就可以跟踪打开的请求等),因此准确地知道您试图执行的操作非常重要。@JayDorsey这不是应用程序错误,上次我修改配置时,我得到了相同的输出,但有错误代码200@ThomasWalpole我正在尝试在docker内部运行测试。web
包含我的应用程序。我的tests和selenium应用程序在docker中,但在单独的容器中。是的,我正在尝试在web
docker实例中运行测试@JayDorsey测试在没有Docker的情况下在本地运行。您在该配置中进行了很多操作。托马斯也许能帮你解决这个问题,贝特