Hi, I'm trying to dockerize cuprite for my app, and I started a blank rails app to figure out where I've gone wrong and I am reproducing the same issue in my blank rails app, which is that my network alias isn't working for the APP_HOST
The tests pass if I don't use a custom hostname/network alias, but we need that to work for subdomain-dependent specs
I started with the blog post https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing#dockerizing-system-tests and wound up here trying to figure things out piece by piece
# docker-compose.yml
volumes:
volume_name:
name: cuprite_test
services:
app:
environment:
CHROME_URL: ${CHROME_URL:-http://chrome:3333}
APP_HOST: ${APP_HOST:-app.mysite.local}
build: .
working_dir: /r
command: bundle exec rails s
volumes:
- .:/r
- ~/.npm:/root/.npm
- .bundle:/usr/local/bundle
ports:
- 3001:3001
- 3002:3002
depends_on:
- db
networks:
default:
aliases:
- app.mysite.local
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgresql
POSTGRES_PASSWORD: password
chrome:
# Currently, Apple M1 is only supported in unnumbered "latest" versions.
# See https://github.com/browserless/chrome/issues/1393
image: browserless/chrome:latest
ports:
- "3333:3333"
# Mount application source code to support file uploading
# (otherwise Chrome won't be able to find files).
# NOTE: Make sure you use absolute paths in `#attach_file`.
volumes:
- .:/app:cached
environment:
# By default, it uses 3000, which is typically used by Rails.
PORT: 3333
# Set connection timeout to avoid timeout exception during debugging
# https://docs.browserless.io/docs/docker.html#connection-timeout
CONNECTION_TIMEOUT: 600000
# spec/system/support/capybara_setup.rb
# Usually, especially when using Selenium, developers tend to increase the max wait time.
# With Cuprite, there is no need for that.
# We use a Capybara default value here explicitly.
Capybara.default_max_wait_time = 2
# Normalize whitespaces when using `has_text?` and similar matchers,
# i.e., ignore newlines, trailing spaces, etc.
# That makes tests less dependent on slightly UI changes.
Capybara.default_normalize_ws = true
# Where to store system tests artifacts (e.g. screenshots, downloaded files, etc.).
# It could be useful to be able to configure this path from the outside (e.g., on CI).
Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")
Capybara.singleton_class.prepend(Module.new do
attr_accessor :last_used_session
def using_session(name, &block)
self.last_used_session = name
super
ensure
self.last_used_session = nil
end
end)
Capybara.server_host = "0.0.0.0"
Capybara.server_port = 3002
# Use a hostname that could be resolved in the internal Docker network
Capybara.app_host = "http://#{ENV.fetch('APP_HOST', `hostname`.strip&.downcase || '0.0.0.0')}"
All the other system support files are exactly as you have them, except we don't use Webpacker
# spec/system/hello_world_spec.rb
require "system_helper"
RSpec.describe "Hello world" do
scenario do
visit root_path
expect(page.body).to have_content("Hello cuprite world")
# PASSES if not using custom hostname, but we need custom hostnames with subdomains
end
end
# config/routes.rb
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
# Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
# get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
# get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
# Defines the root path route ("/")
root "welcome#show"
end
Hello world
Failure/Error: visit root_path
Ferrum::StatusError:
Request to http://app.mysite.local:3002/ failed (net::ERR_NAME_NOT_RESOLVED)
[Screenshot Image]: tmp/capybara/failures_r_spec_example_groups_hello_world_example_at___spec_system_hello_world_spec_rb_4_5.png
# /usr/local/bundle/gems/ferrum-0.15/lib/ferrum/page.rb:111:in 'Ferrum::Page#go_to'
# /usr/local/bundle/gems/cuprite-0.15.1/lib/capybara/cuprite/browser.rb:75:in 'Capybara::Cuprite::Browser#visit'
# /usr/local/bundle/gems/cuprite-0.15.1/lib/capybara/cuprite/driver.rb:57:in 'Capybara::Cuprite::Driver#visit'
# /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/session.rb:281:in 'Capybara::Session#visit'
# /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in 'Method#call'
# /usr/local/bundle/gems/capybara-3.40.0/lib/capybara/dsl.rb:52:in 'Capybara::DSL#visit'
# ./spec/system/hello_world_spec.rb:5:in 'block (2 levels) in <main>'
# ./spec/system/support/better_rails_system_tests.rb:25:in 'block (2 levels) in <main>'
Finished in 0.91628 seconds (files took 0.73827 seconds to load)
4 examples, 1 failure, 2 pending
The generated spec/requests/welcome_spec.rb that came with rails g controller welcome show is passing (200 OK)
I added the text Hello cuprite world to the welcome/show.html.erb file and it was passing before I tried using a custom host name. We need the custom hostname working because we have subdomain-dependent specs.
commands:
docker compose up -d chrome
docker compose run --it app bash
bundle exec rspec
Here is the full source in case it helps:
https://github.com/joemsak/cuprite-test
Any help or insight offered would be greatly appreciated, thank you!
Hi, I'm trying to dockerize cuprite for my app, and I started a blank rails app to figure out where I've gone wrong and I am reproducing the same issue in my blank rails app, which is that my network alias isn't working for the APP_HOST
The tests pass if I don't use a custom hostname/network alias, but we need that to work for subdomain-dependent specs
I started with the blog post https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing#dockerizing-system-tests and wound up here trying to figure things out piece by piece
All the other system support files are exactly as you have them, except we don't use Webpacker
The generated
spec/requests/welcome_spec.rbthat came withrails g controller welcome showis passing (200 OK)I added the text
Hello cuprite worldto thewelcome/show.html.erbfile and it was passing before I tried using a custom host name. We need the custom hostname working because we have subdomain-dependent specs.commands:
Here is the full source in case it helps:
https://github.com/joemsak/cuprite-test
Any help or insight offered would be greatly appreciated, thank you!