Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update capybara configs #156

Open
dkniffin opened this issue Apr 3, 2019 · 0 comments
Open

Update capybara configs #156

dkniffin opened this issue Apr 3, 2019 · 0 comments
Labels
New Rails Config New functionality to be added to the generated Rails app

Comments

@dkniffin
Copy link
Contributor

dkniffin commented Apr 3, 2019

Instead of requiring chromedriver to be installed globally, we should add the webdrivers gem, and change our capybara config to this:

# frozen_string_literal: true

require "webdrivers"

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu] }
  )

  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

RSpec.configure do |config|
  config.include Capybara::DSL

  config.after do
    Capybara.reset_sessions!
  end

  config.before(:each, type: :system) do
    driven_by :headless_chrome
  end
end

If we continue building apps with SPAs included in the app like we're doing on some recent projects, we should also add something like

  config.before(:suite) do
    examples = RSpec.world.filtered_examples.values.flatten
    has_system_tests = examples.any? { |example| example.metadata[:type] == :system }
    if has_system_tests
      commands = [
        "rm -rf public/build",
        "rm -rf public/index.html",
        "cd frontend",
        "yarn install",
        "yarn build",
        "cd ..",
        "mv frontend/build public/build",
        "mv public/build/index.html public/index.html"
      ]
      command = commands.join(" && ")
      system(command)
      exitstatus = $CHILD_STATUS.exitstatus
      exit exitstatus if exitstatus.nonzero?
    end
  end

With these changes, we can also remove a few things from travis.yml (sudo apt-get update, sudo apt-get install chromium-chromedriver, export PATH=$PATH:/usr/lib/chromium-browser/, export DISPLAY=:99.0, sh -e /etc/init.d/xvfb start, and sleep 3)

@dkniffin dkniffin added the New Rails Config New functionality to be added to the generated Rails app label May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Rails Config New functionality to be added to the generated Rails app
Projects
None yet
Development

No branches or pull requests

1 participant