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 1 commit
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
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ services:
target: development
depends_on:
- db
- selenium
ports:
- 3000:3000
restart: always
Expand All @@ -38,3 +39,11 @@ 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
shm_size: 2g
31 changes: 31 additions & 0 deletions spec/features/click_login_link_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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'
visit root_path
expect(page).to have_content('UC Berkeley GeoData Repository')
end
end
27 changes: 27 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'

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/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try copying exactly what we got working in TIND-QA, which is a simplified version of what's configured for Framework. The option arguments and preferences differ a bit between the two and it's not immediately obvious what would cause a problem, so best to start with a known working config.

Copy link
Contributor

@danschmidt5189 danschmidt5189 Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ha! Per our discussion off-GitHub—a problem is that the Selenium container makes requests to localhost:3000, but the actual address (from its perspective) is app:3000. IIRC from having worked with Capybara like this in the past, something in the stack (Chrome?) will complain about hitting a hostname with an invalid TLD, so you may have to use app.test:3000 with a network alias added to your compose file:

services:
  app:
    networks:
      default:
        aliases:
          - app.test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had to reconfigure shm:

  1. Removed shm_size from the Compose file
  2. Added the Chrome argument --disable-dev-shm-usage

Having done both of those I'm now able to run the feature specs locally on an M-chip MacBook.

)

end

Capybara.default_driver = Capybara.javascript_driver = :remote_selenium_headless

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

Expand Down
Loading