Make capybara work in the devcontainer

This commit is contained in:
Daniel O'Connor
2024-01-17 13:38:19 +00:00
parent 006e7553e5
commit 2f027f4f0d
3 changed files with 25 additions and 4 deletions

View File

@@ -15,6 +15,10 @@ ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev,.preview.app.github.dev,.app.git
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends bash-completion
# Chrome for testing packages. https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-doesnt-launch-on-linux
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils
# [Optional] Uncomment this line to install additional gems.
# RUN gem install <your-gem-names-here>

View File

@@ -14,7 +14,7 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
"forwardPorts": [3000, 5432, 9200],
"forwardPorts": [3000, 5432, 9200, 8081],
// Use 'postCreateCommand' to run commands after the container is created.
// these don't actually work as postCreateCommands, you need to run them manually

View File

@@ -21,10 +21,27 @@ require 'capybara/rspec'
require 'selenium/webdriver'
require 'capybara-screenshot/rspec'
require 'webdrivers'
# TODO: We may want to trial options.add_argument('--disable-dev-shm-usage') ### optional
Capybara.default_driver = :selenium_chrome_headless
Capybara.javascript_driver = :selenium_chrome_headless
# Required for running in the dev container
Capybara.register_driver :selenium_chrome_customised_headless do |app|
options = Selenium::WebDriver::Options.chrome
options.add_argument("--headless")
options.add_argument("--no-sandbox")
# driver = Selenium::WebDriver.for :chrome, options: options
Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end
# Ability to pass in flags to
if ENV["CAPYBARA_DRIVER"]
Capybara.default_driver = ENV["CAPYBARA_DRIVER"].to_sym
Capybara.javascript_driver = ENV["CAPYBARA_DRIVER"].to_sym
else
Capybara.default_driver = :selenium_chrome_customised_headless
Capybara.javascript_driver = :selenium_chrome_customised_headless
end
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.tr(' ', '-').gsub(%r{^.*/spec/}, '')}"