Skip to content

Commit

Permalink
add chrome-server service to run integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 19, 2023
1 parent c9b3e32 commit c1cab53
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem 'capybara'
gem 'selenium-webdriver'
gem 'webdrivers'
#gem 'webdrivers'
end


Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2023.1003)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
msgpack (1.7.2)
multi_json (1.15.0)
Expand Down Expand Up @@ -306,6 +307,9 @@ GEM
newrelic_rpm (9.6.0)
base64
nio4r (2.5.9)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
Expand Down Expand Up @@ -530,10 +534,6 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.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)
Expand All @@ -545,6 +545,7 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
ruby
x86_64-darwin-23
x86_64-linux
x86_64-linux-musl
Expand Down Expand Up @@ -623,7 +624,6 @@ DEPENDENCIES
tzinfo-data
view_component (~> 2.72)
web-console
webdrivers
will_paginate (~> 3.0)

BUNDLED WITH
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
x-app: &default-app
image: agroportal/ontoportal_web_ui:development
image: agroportal/ontoportal_web_ui:test
env_file:
- ".env"
tty: true
Expand Down Expand Up @@ -65,12 +65,18 @@ services:
depends_on:
- db
- cache
- chrome-server
network_mode: 'host'
environment:
BUNDLE_WITHOUT: ''
DB_HOST: 127.0.0.1
CACHE_HOST: 127.0.0.1

chrome-server:
image: selenium/standalone-chrome:112.0-chromedriver-112.0-grid-4.9.0-20230421
shm_size: 2g
ports:
- "4444:4444"
- "7900:7900"

volumes:
mysql-data:
Expand Down
72 changes: 72 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require "test_helper"
require_relative 'helpers/application_test_helpers'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include ApplicationTestHelpers::Ontologies
include ApplicationTestHelpers::Users
include ApplicationTestHelpers::Users
include ApplicationTestHelpers::Categories
include ApplicationTestHelpers::Groups

driven_by :selenium, using: :chrome, options: {
browser: :remote,
url: "http://localhost:4444"
}

def login_in_as(user)
visit login_index_url

# Fill in the login form
fill_in 'user_username', with: user.username
fill_in 'user_password', with: user.password

# Click the login button
click_button 'Login'
end

def tom_select(selector, values)

multiple = values.is_a?(Array)


real_select = "[name='#{selector}']"

# Click on the Tom Select input to open the dropdown
find("#{real_select} + div").click
sleep 1

return unless page.has_selector?("#{real_select} + div > .ts-dropdown")

if multiple
# reset the input to empty
all("#{real_select} + div > .ts-control > .item .remove").each do |element|
element.click
end

page.execute_script("document.querySelector(\"#{real_select} + div > .ts-control\").innerHTML = '';")
else
values = Array(values)
end

within "#{real_select} + div > .ts-dropdown > .ts-dropdown-content" do


values.each do |value|
if page.has_selector?('.option', text: value)
find('.option', text: value).click
end
end
end

if multiple
find("#{real_select} + div").click
sleep 1
end
end


def date_picker_fill_in(selector, value)
page.execute_script("document.querySelector(\"[name='#{selector}']\").flatpickr().setDate('#{value}')")
end

end
40 changes: 40 additions & 0 deletions test/helpers/application_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'rails/test_help'
module ApplicationTestHelpers
module Users
def sign_in_as(username)
user = fixtures(:users)[username]
logged_in_user = LinkedData::Client::Models::User.authenticate(user.username, user.password)
if logged_in_user && !logged_in_user.errors
logged_in_user = create_user(user)
end
session[:user] = logged_in_user
end

def create_user(user)
LinkedData::Client::Models::User.new(values: user.to_h).save
end
end


module Ontologies
def create_ontology(ontology)
LinkedData::Client::Models::Ontology.new(values: ontology.to_h).save
end
end

module Categories
def create_category(category)
created = LinkedData::Client::Models::Category.new(values: category.to_h).save
return category if created.errors
created
end
end

module Groups
def create_group(group)
created = LinkedData::Client::Models::Group.new(values: group.to_h).save
return group if created.errors
created
end
end
end
8 changes: 5 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: 1)

# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all

# Add more helper methods to be used by all tests here...


Capybara.server_host = "0.0.0.0"
Capybara.app_host = "http://#{Socket.gethostname}:#{Capybara.server_port}"

end

0 comments on commit c1cab53

Please sign in to comment.