environment:
Rails: 5.1.5
Ruby: 2.5.0
capybara:2.18.0
rspec-rails: 3.7.2
selenium-webdriver: 3.10.0
I'm a beginner at Docker.We are currently creating a development environment with docker-compose as follows, and then testing capybara with rspec (system spec), but we are having trouble knowing how to test subdomains.
docker-compose.yml
services:
nginx:
image:nginx:alpine
container_name —my_nginx
links:
- app
ports:
- "80:80"
volumes:
- .:/app
depend_on:
- chrome
app:
build:
context:.
command:bash-c "rm-ftmp/pids/server.pid&./bin/webpack-dev-server&bundle exec rails-b 0.0.0.0-p 3000"
working_dir: /app
container_name —my_app
hostname:app
ports:
- '3000:3000'
expose:
- 3000
volumes:
- .:/app
- rails_public: /app/public
- rails_log: /app/log
- bundle: /app/vendor/bundle
- /app/node_modules
links:
- postgres
- redis
depend_on:
- postgres
- chrome
tty —true
stdin_open —true
environment:
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
chrome:
container_name —my_chrome
image —Selenium/standalone-chrome
ports:
- 4444:4444
volumes:
- .:/app
Abbreviated.
capybara.rb
require "capybara/rspec"
require "selenium-webdriver"
Capybara.register_driver: selenium_remote do|app|
capabilities=Selenium::WebDriver::Remote::Capabilities.chrome(
ChromeOptions: {
args: ["--headless", "--no-sandbox", "--disable--gpu", "--window-size=1280x800", ],
},
)
Capybara::Selenium::Driver.new(app,
url: "http://chrome:4444/wd/hub",
browser: :remote,
desired_capabilities:capabilities)
end
Capybara.run_server=false
Capybara.default_driver=: selenium_remote
If spec_helper.rb is configured for the following , non-subdomain tests will run successfully:
RSpec.configure do | config |
config.before:each, type::system do
drive_by — selenium_remote
Capybara.app_host="http://{IPSocket.getaddress(Socket.gethostname)}"
Capybara.always_include_port=true
end
Abbreviated.
However, I just don't know how to test the subdomain.
As for the image, I am thinking that /etc/hosts
will be able to check the IP and assign a subdomain to the app container and access it, but I would appreciate it if you could let me know if there is a good way to use extra_hosts on docker-compose.Thank you for your cooperation.
Tried:
①Capybara.app_host="http://admin.{IPSocket.getaddress(Socket.gethostname)}"
→ IP address could not be used.
app Enter app container /etc/hosts
to assign app container IP to admin.app
and set Capybara.app_host="http://admin.app"
→In the first place, Capybara.app_host="http://app"
cannot be accessed, and the following error appears when Capybara.app_host="http://app:3000"
.
HTTP parse error, malformed request():#<Puma::HttpParserError: Invalid HTTP format, parsing failures.>
<Capybara.app_host="http://nginx"
and settings
→ You can connect to a place that is not a subdomain, but somehow you access the development DB ( )
n Enter the nginx container and assign the IP of the nginx container to admin.nginx
with Capybara.app_host="http://admin.nginx"
→ Connection failed.
Capybara.server_host='0.0.0.0'
Why don't you set up ?
© 2024 OneMinuteCode. All rights reserved.