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

setup selenium testing #24

Open
wants to merge 6 commits into
base: DP-1025-upgrade-omniauth
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ end

group :test do
gem 'capybara'
gem 'rspec', '~> 3.13'
gem 'rspec_junit_formatter', require: false
gem 'selenium-webdriver'
gem 'simplecov', '~> 0.21', require: false
Expand Down
23 changes: 14 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ GEM
deep_merge (1.2.2)
deprecation (1.1.0)
activesupport
devise (4.9.3)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand All @@ -144,7 +144,7 @@ GEM
faraday-net_http_persistent (2.1.0)
faraday (~> 2.5)
net-http-persistent (~> 4.0)
faraday-retry (2.2.0)
faraday-retry (2.2.1)
faraday (~> 2.0)
ffi (1.16.3)
ffi-compiler (1.3.2)
Expand Down Expand Up @@ -242,7 +242,7 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.0.0)
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0305)
Expand All @@ -264,11 +264,11 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.3-aarch64-linux)
nokogiri (1.16.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-darwin)
nokogiri (1.16.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
nokogiri (1.16.4-x86_64-linux)
racc (~> 1.4)
oj (3.16.3)
bigdecimal (>= 3.0)
Expand Down Expand Up @@ -340,7 +340,7 @@ GEM
rdoc (6.6.3.1)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.5.0)
reline (0.5.1)
io-console (~> 0.5)
request_store (1.6.0)
rack (>= 1.4)
Expand All @@ -355,6 +355,10 @@ GEM
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
Expand All @@ -374,7 +378,7 @@ GEM
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.63.0)
rubocop (1.63.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -401,7 +405,7 @@ GEM
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.2)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
Expand Down Expand Up @@ -510,6 +514,7 @@ DEPENDENCIES
rack-timeout (~> 0.6.3)
rails (~> 7.0.8)
rsolr (>= 1.0, < 3)
rspec (~> 3.13)
rspec-rails
rspec_junit_formatter
rubocop
Expand Down
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
config.hosts << 'app.test'
end
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ services:
target: development
depends_on:
- db
- selenium
networks:
default:
aliases:
- app.test
ports:
- 3000:3000
restart: always
Expand All @@ -38,3 +43,15 @@ services:
SOLR_URL: http://solr:8983/solr/geodata-test
volumes:
- ./:/opt/app:delegated

selenium:
image: selenium/standalone-chrome
ports:
- 4444:4444
- 7900:7900
platform: linux/amd64
networks:
default:
aliases:
- selenium.test
shm_size: 2g
33 changes: 33 additions & 0 deletions spec/features/click_login_link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# require 'spec_helper'
require 'rails_helper'

# RSpec.feature 'Clicking login link on root page', type: :feature do
# scenario 'User clicks login link and is redirected login page' do
# Rails.logger.info 'User is logged in'
# visit root_path
# click_link 'login'
# logger.info("PPPPP-#{user_calnet_omniauth_authorize_path}")
# expect(page).to have_current_path(user_calnet_omniauth_authorize_path)
# end
# end


# describe 'User Util Links' do
# it 'has link' do
# visit root_path
# click_link 'login'
# # logger.info("PPPPP-#{user_calnet_omniauth_authorize_path}")
# # expect(page).to have_current_path(user_calnet_omniauth_authorize_path)
# end
# end

RSpec.feature 'Homepage', type: :feature, js: true do
include Capybara::DSL
scenario 'User visits the homepage' do
# root_path = 'https://www.google.com'
# sleep(60)
root_path = 'http://app.test:3000/'
visit root_path
expect(page).to have_content('UC Berkeley GeoData Repository')
end
end
50 changes: 50 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,56 @@
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'

################## from TIND_QA ######################

# require 'rspec'
require 'capybara/rspec'
require 'selenium-webdriver'

Capybara.register_driver(:remote) do |app|
chrome_args = %w[
--disable-smooth-scrolling
--headless
--window-size=2560,1344
]

chrome_prefs = {
'download.prompt_for_download' => false,
'download.default_directory' => '/tmp'
}

chrome_options = ::Selenium::WebDriver::Chrome::Options.new(args: chrome_args, prefs: chrome_prefs).tap do |options|
# NOTE: Different Selenium/Chrome versions set download directory differently -- see
# https://github.com/teamcapybara/capybara/blob/3.38.0/spec/selenium_spec_chrome.rb#L15-L20
if (download_dir = chrome_prefs['download.default_directory'])
options.add_preference(:download, default_directory: download_dir)
end
end

capabilities = [
chrome_options,
Selenium::WebDriver::Remote::Capabilities.new(
'goog:loggingPrefs' => {
browser: 'ALL', driver: 'ALL'
}
)
]

Capybara::Selenium::Driver.new(app,
browser: :remote,
capabilities:,
url: "http://#{ENV['SELENIUM_HOST'] || 'selenium.test'}:4444/",
)
end

Capybara.default_driver = Capybara.javascript_driver = :remote
Capybara.app_host = 'http://app.test:3000'
Capybara.server_host = '0.0.0.0'
Capybara.always_include_port = true

#############


RSpec.configure do |config|
config.use_transactional_fixtures = false

Expand Down
76 changes: 76 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,82 @@
# require 'rspec_junit_formatter'
# SimpleCov.start 'rails'

### testing code ###
# Capybara.register_driver :remote_selenium_headless do |app|
# options = Selenium::WebDriver::Chrome::Options.new
# options.add_argument('--headless=new')
# options.add_argument('--no-sandbox')
# # options.add_argument('--disable-dev-shm-usage')
# # options.add_argument('--disable-gpu')
# options.add_argument('--window-size=2560,1344')
# options.add_argument('--disable-smooth-scrolling')
# capabilities = [
# options,
# Selenium::WebDriver::Remote::Capabilities.new(
# 'goog:loggingPrefs' => {
# browser: 'ALL', driver: 'ALL'
# }
# )
# ]

# Capybara::Selenium::Driver.new(app,
# browser: :remote,
# capabilities:,
# url: "http://#{ENV['SELENIUM_HOST'] || 'selenium'}:4444/",
# )

# end

# Capybara.default_driver = Capybara.javascript_driver = :remote_selenium_headless
### testing code end ###


# ################## from TIND_QA ######################

# require 'rspec'
# require 'capybara/rspec'
# require 'selenium-webdriver'

# Capybara.register_driver(:remote) do |app|
# chrome_args = %w[
# --window-size=2560,1344
# --disable-smooth-scrolling
# ]

# chrome_prefs = {
# 'download.prompt_for_download' => false,
# 'download.default_directory' => '/tmp',
# }

# chrome_options = ::Selenium::WebDriver::Chrome::Options.new(args: chrome_args, prefs: chrome_prefs).tap do |options|
# # NOTE: Different Selenium/Chrome versions set download directory differently -- see
# # https://github.com/teamcapybara/capybara/blob/3.38.0/spec/selenium_spec_chrome.rb#L15-L20
# if (download_dir = chrome_prefs['download.default_directory'])
# options.add_preference(:download, default_directory: download_dir)
# end
# end

# capabilities = [
# chrome_options,
# Selenium::WebDriver::Remote::Capabilities.new(
# 'goog:loggingPrefs' => {
# browser: 'ALL', driver: 'ALL'
# }
# )
# ]

# Capybara::Selenium::Driver.new(app,
# browser: :remote,
# capabilities:,
# url: "http://#{ENV['SELENIUM_HOST'] || 'selenium'}:4444/",
# )
# end

# Capybara.default_driver = Capybara.javascript_driver = :remote

# #############


# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
Expand Down
Loading