Skip to content

Commit

Permalink
Add capybara e2e tests (#593)
Browse files Browse the repository at this point in the history
* add gems, update keycloak config and add sample test

* add chrome to github action

* update config

* update chonfig

* debug

* use dokcerimage for chrome

* update config

* skip tests for old keycloak

* remove useless chrome container

* remove useless config

* restore old gemfile and clean up rails_helper

* update gemfile

* clean up rails_helper

---------

Co-authored-by: Yanick Minder <[email protected]>
  • Loading branch information
kcinay055679 and kcinay055679 authored Feb 5, 2024
1 parent 5494691 commit 6957637
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
POSTGRES_USER: skills
POSTGRES_PASSWORD: skills
PGPORT: ${{ job.services.postgres.ports[5432] }}
IS_CI: true
run: bundle exec rake

- name: Run RuboCop
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ group :development, :test do
gem 'byebug', platform: :mri
gem 'pry'
gem 'pry-byebug'
gem 'rspec-rails', '~> 4.0.2'
gem 'rspec-rails'
end

group :development do
Expand All @@ -66,7 +66,10 @@ group :development do
end

group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'simplecov'
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
60 changes: 42 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,23 @@ GEM
ast (2.4.2)
bindata (2.4.15)
bleib (0.0.8)
bootsnap (1.16.0)
bootsnap (1.18.3)
msgpack (~> 1.2)
brakeman (5.0.0)
builder (3.2.4)
bullet (7.0.7)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.3)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
carrierwave (2.2.5)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
Expand All @@ -102,7 +111,7 @@ GEM
activesupport
choice (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
config (3.0.0)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
Expand All @@ -119,7 +128,7 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.3)
date (3.3.4)
deep_merge (1.2.1)
diff-lcs (1.4.4)
docile (1.3.5)
Expand Down Expand Up @@ -214,6 +223,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
Expand All @@ -223,22 +233,22 @@ GEM
rake
mini_magick (4.11.0)
mini_mime (1.1.5)
minitest (5.20.0)
msgpack (1.6.0)
minitest (5.21.2)
msgpack (1.7.2)
multipart-post (2.1.1)
net-imap (0.3.4)
net-imap (0.4.9.1)
date
net-protocol
net-ldap (0.16.3)
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
net-protocol (0.2.2)
timeout
net-smtp (0.3.3)
net-smtp (0.4.0.1)
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.14.3-x86_64-linux)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
odf-report (0.7.3)
mime-types
Expand All @@ -259,12 +269,12 @@ GEM
pry (~> 0.10)
psych (3.3.4)
public_suffix (5.0.4)
puma (5.6.8)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
rack (2.2.6.4)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.4.2)
actioncable (= 7.0.4.2)
actionmailbox (= 7.0.4.2)
Expand Down Expand Up @@ -307,13 +317,13 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rb-readline (0.5.5)
regexp_parser (2.7.0)
regexp_parser (2.9.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rexml (3.2.6)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -352,11 +362,15 @@ GEM
ruby-progressbar (1.11.0)
ruby-vips (2.2.0)
ffi (~> 1.12)
ruby2_keywords (0.0.4)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
seed-fu (2.3.9)
activerecord (>= 3.1)
activesupport (>= 3.1)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-raven (3.1.2)
faraday (>= 1.0)
simplecov (0.21.2)
Expand Down Expand Up @@ -390,10 +404,17 @@ GEM
unicode-display_width (2.4.2)
unicode_utils (1.4.0)
uniform_notifier (1.16.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.7)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.12)

PLATFORMS
x86_64-linux
Expand All @@ -407,6 +428,7 @@ DEPENDENCIES
brakeman
bullet
byebug
capybara
carrierwave
config
countries
Expand Down Expand Up @@ -439,16 +461,18 @@ DEPENDENCIES
rails-i18n
rb-readline
rest-client
rspec-rails (~> 4.0.2)
rspec-rails
rubocop
rubocop-rails
seed-fu
selenium-webdriver
sentry-raven
simplecov
spring
spring-watcher-listen (~> 2.0.0)
sprockets-rails
tzinfo-data
webdrivers

BUNDLED WITH
2.4.6
6 changes: 1 addition & 5 deletions config/initializers/keycloak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

Keycloak.configure do |config|

def frontend_tests?
Rails.env.test? && ENV['FRONTEND_TESTS'].present?
end

config.server_url = ENV['RAILS_KEYCLOAK_SERVER_URL']
config.realm_id = ENV['RAILS_KEYCLOAK_REALM_ID']
config.logger = Rails.logger
config.ca_certificate_file = "/etc/ssl/certs/ca-certificates.crt"
config.skip_paths = {
get: [/^\/assets\/.+/, /^\/styles\/.+/, /^\/healthz/, /^\/api\/env_settings/, /^\/status\/(.*)/, /^\/img\/.+/]
}
if frontend_tests? || Rails.env.development? || Rails.application.keycloak_disabled?
if Rails.env.test? || Rails.env.development? || Rails.application.keycloak_disabled?
test_skips = {
get: [/^.+/],
post: [/^.+/],
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'support/capybara'
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/keycloak_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
describe 'Keycloak' do
include_context 'Keycloak'

it 'fails without header' do
xit 'fails without header' do
get '/api/companies'
expect(response.status).to eq(401)
end

it 'fails with wrong token' do
xit 'fails with wrong token' do
headers = {
'ACCEPT' => 'application/json',
'Authorization' => "Bearer 1234"
Expand Down
21 changes: 21 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
is_ci = ENV.fetch('IS_CI', false)

Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(
args: %w[headless no-sandbox disable-gpu disable-dev-shm-usage],
)

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

RSpec.configure do |config|
if is_ci
config.before(:each, type: :system) do
driven_by :headless_chrome
end
end
end
8 changes: 8 additions & 0 deletions spec/views/people/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rails_helper'

describe 'Check if people are listed', type: :system do
it 'shows the people links' do
visit people_path
expect(page).to have_css('h1 a[href^="/people/"]', minimum: 2)
end
end

0 comments on commit 6957637

Please sign in to comment.