I have created a docker compose file for doing Capybara tests inside a container. The problem i'm currently facing to is that i can't find a ability to to route the subdomains of my lvh.me domain. When I add lvh.me to the hosts file of Selenium I get the same result that my tests are failing. In which way can I add some routing for subdomains to Selenium to accept subdomains like {{user}}.lvh.me:3001
My Capybara configuration
Capybara.register_driver :selenium do |app|
Capybara.app_host = "http://0.0.0.0:3001"
Capybara.server_host = '0.0.0.0'
Capybara.server_port = '3001'
Capybara.always_include_port = true
args = ['--no-default-browser-check', '--headless', '--start-maximized']
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => args})
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: "http://hub:4444/wd/hub",
desired_capabilities: caps
)
end
Capybara.configure do |config|
config.default_driver = :rack_test
config.javascript_driver = :selenium
end
And my docker compose file
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
redis:
image: redis
volumes:
- ./tmp/redis:/var/lib/redis/data
web:
build: .
environment:
- REDIS_URL=redis://redis
- DATABASE_HOST=db
command: sh "/myapp/docker-entrypoint.sh"
volumes:
- .:/myapp
links:
- db
- redis
- hub
depends_on:
- db
- redis
ports:
- "3001:3001"
- "3000:3000"
hub:
container_name: hub
image: selenium/hub:3.9
ports:
- "4444:4444"
selenium:
container_name: selenium
image: selenium/node-chrome:3.9
environment:
HUB_PORT_4444_TCP_ADDR: hub
HUB_PORT_4444_TCP_PORT: 4444
depends_on:
- hub
links:
- hub
Firstly you shouldn't be specifying the Capybara config inside the driver registration. Secondly, this is going to assume you're running your tests on the web docker instance -- if you're actually trying to run your tests on the host then things would be slightly different.
Capybara.app_host needs to be set to a URL that points to where the app under test is running from the perspective of the browser. In your case the browser is running on the selenium docker instance, and the tests should start the AUT on the web instance - that would mean Capybara.app_host should be http://web (port is not needed since you've specified alway_include_port). That means you should end up with
Capybara.register_driver :selenium do |app|
args = ['--no-default-browser-check', '--headless', '--start-maximized']
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => args})
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: "http://hub:4444/wd/hub",
desired_capabilities: caps
)
end
Capybara.configure do |config|
config.app_host = "http://web"
config.server_host = '0.0.0.0'
config.server_port = '3001'
config.always_include_port = true
config.default_driver = :rack_test
config.javascript_driver = :selenium
end
Your next issue it you want to use which lvh.me which resolves to 127.0.0.1 but you need it to resolve to whatever ip is assigned to the web docker instance. If you have a fixed number of subdomains used in your tests you should be able to handle that via link aliases specified in the selenium docker instance config - https://docs.docker.com/compose/compose-file/#links - or via network aliases if you specify networks in your docker compose config - https://docs.docker.com/compose/compose-file/#aliases. If you do actually need to resolve wildcard (*.lvh.me) then you'll need to run your own DNS server (possibly in your docker setup) with a wildcard CNAME entry that resolves *.lvh.me to web
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With