Skip to content

Commit

Permalink
using chromedriver for javascript driver in feature tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jenlindner committed Jan 5, 2018
1 parent 63672e5 commit b345e61
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 55 deletions.
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ sudo: false
cache: bundler
dist: trusty

addons:
apt:
packages:
- qt5-default
- libqt5webkit5-dev
- gstreamer1.0-plugins-base
- gstreamer1.0-tools gstreamer1.0-x
- google-chrome-stable

before_install:
- gem update --system
- gem install bundler
- google-chrome-stable --headless --disable-gpu -no-sandbox --browsertime.xvfb --remote-debugging-port=9222 http://localhost &

jdk:
- oraclejdk8
rvm:
- 2.4.2
before_script:
- bundle exec rake db:create
script:
- bundle exec rake
- xvfb-run -a bundle exec rake ci
services:
- redis-server
- postgresql
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ group :development, :test do
end

group :test do
gem 'capybara', '~> 2.15.4'
gem 'capybara', '~> 2.15.4'
gem 'chromedriver-helper'
gem 'coveralls', require: false
gem 'factory_bot_rails', '~> 4.8.0'
gem 'poltergeist'
gem 'selenium-webdriver'
end
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
almond-rails (0.1.0)
rails (>= 4.2, < 6)
archive-zip (0.7.0)
io-like (~> 0.3.0)
arel (7.1.4)
ast (2.3.0)
autoprefixer-rails (7.1.6)
Expand Down Expand Up @@ -177,13 +179,15 @@ GEM
mime-types (>= 1.16)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (1.1.0)
archive-zip (~> 0.7.0)
nokogiri (~> 1.6)
citeproc (1.0.6)
namae (~> 0.8)
citeproc-ruby (1.1.8)
citeproc (>= 1.0.4, < 2.0)
csl (~> 1.4)
clipboard-rails (1.7.1)
cliver (0.3.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand Down Expand Up @@ -416,6 +420,7 @@ GEM
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
inflecto (0.0.2)
io-like (0.3.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
Expand Down Expand Up @@ -559,10 +564,6 @@ GEM
parser (2.4.0.0)
ast (~> 2.2)
pg (0.21.0)
poltergeist (1.17.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
posix-spawn (0.3.13)
power_converter (0.1.2)
powerpack (0.1.1)
Expand Down Expand Up @@ -867,6 +868,7 @@ DEPENDENCIES
capistrano-rails
capistrano-sidekiq (~> 0.20.0)
capybara (~> 2.15.4)
chromedriver-helper
citeproc-ruby (~> 1.0, >= 1.0.6)
coffee-rails (~> 4.2)
coveralls
Expand All @@ -888,7 +890,6 @@ DEPENDENCIES
listen (~> 3.0.5)
okcomputer (~> 1.17, >= 1.17.1)
pg
poltergeist
puma (~> 3.0)
rails (~> 5.0.6)
rsolr (>= 1.0)
Expand Down
Binary file added spec/.DS_Store
Binary file not shown.
24 changes: 15 additions & 9 deletions spec/features/autocomplete_mesh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

scenario 'autocompleting MeSH terms in the subject field on form' do
visit '/concern/etds/new'
# Add a file first
click_link "Files" # switch tab
expect(page).to have_content "Add files"
within('span#addfiles') do
attach_file('files[]', File.absolute_path(file_fixture('pdf-sample.pdf')), visible: false)
end
click_link "Description"

expect(page).to have_content('Additional fields')
click_on 'Additional fields'

Expand All @@ -28,22 +36,20 @@
select 'In Copyright', from: 'Rights'
find('body').click

# Add a file
click_link "Files" # switch tab
expect(page).to have_content "Add files"
within('span#addfiles') do
attach_file('files[]', File.absolute_path(file_fixture('pdf-sample.pdf')), visible: false)
end
expect(page).to have_content('Delete')

# Submit the form
expect(page).to have_selector('#with_files_submit')
find('#with_files_submit').click
click_on('Save')

# wait until we have a record
persisted_etd = Etd.where(title: 'MeSH Test') while persisted_etd.nil?

# Check that the page has Sulfamerazine
expect(page).to have_content 'Sulfamerazine'
expect(page).to have_content 'MeSH Test'
expect(page).to have_content 'In Copyright'

# clean up
expect(page).to have_content('Delete')
Etd.where(title_tesim: 'MeSH Test').first.delete
expect(Etd.all.size).to eq 0
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/create_etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
click_link 'Files'

within('#addfiles') do
attach_file('files[]', File.absolute_path(file_fixture('pdf-sample.pdf')))
attach_file('files[]', "#{fixture_path}/files/pdf-sample.pdf", visible: false, wait: 10)
end

find('#with_files_submit').click
Expand Down
42 changes: 24 additions & 18 deletions spec/features/edit_etd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@
visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
)
end
scenario 'can edit all of the metadata of an Etd', :perform_enqueued, :datacite_api, js: false do

scenario 'can edit all of the metadata of an Etd', :perform_enqueued, :datacite_api do
ActiveJob::Base.queue_adapter.filter = [DataciteRegisterJob]

visit("/concern/etds/new")

expect(page).to have_content 'Add New Etd'
click_link 'Files'
within('#addfiles') do
attach_file('files[]', "#{fixture_path}/files/pdf-sample.pdf", visible: false, wait: 10)
end

click_link 'Description'

fill_in 'Creator', with: etd[:creator].first
fill_in 'Keyword', with: etd[:keyword].first
# term for rights URI set in factory
select('No Known Copyright', from: 'Rights')

click_link 'Additional fields'

fill_in 'Title', with: etd[:title].first
fill_in 'Description', with: etd[:description].first
# term for license URI set in factory
select('Creative Commons BY-SA Attribution-ShareAlike 4.0 International', from: 'License')
Expand All @@ -48,16 +56,10 @@
select(etd[:resource_type].first, from: 'Document Type')
fill_in 'Rights note', with: etd[:rights_note].first
select(etd[:school].first, from: 'School')
fill_in 'Title', with: etd[:title].first

click_link 'Files'
within('#addfiles') do
attach_file('files[]', "#{fixture_path}/files/pdf-sample.pdf", visible: false, wait: 10)
end

click_on('Save')
# our etd is not persisted here, with phantom js driver, but is with chromedriver.
sleep(2)
# wait until we have a record
persisted_etd = Etd.where(title: "Edited Title") while persisted_etd.nil?
click_on('Edit')

sleep(2)
Expand Down Expand Up @@ -86,15 +88,16 @@
select(etd[:school].last, from: 'School')
fill_in 'Title', with: "Edited Title"
# this seems to be a testing bug due to jobs needing to run to completion in order for record to have files associated with it, but the form should be valid when it's loaded.
# TODO: find out why files aren't here at this point in testing, possible fix test.
# TODO: confirm why files aren't here at this point in testing, possibly fix jobs and remove need to re-add files while editing to get valid form.
click_link 'Files'

within('#addfiles') do
attach_file('files[]', "#{fixture_path}/files/pdf-sample.pdf", visible: false, wait: 10)
end

click_on('Save')
sleep(2)
# wait until we have a record
persisted_etd = Etd.where(title: "Edited Title") while persisted_etd.nil?

expect(page).to have_content "Edited Title"
expect(page).to have_content "Edited Creator"
Expand Down Expand Up @@ -149,21 +152,24 @@
visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
)
visit("/concern/etds/new")
fill_in 'Creator', with: etd[:creator].first
fill_in 'Keyword', with: etd[:keyword].first
# term for rights URI set in factory
select('No Known Copyright', from: 'Rights')
fill_in 'Title', with: etd[:title].first

click_link 'Files'
within('span#addfiles') do
page.attach_file('files[]', "#{fixture_path}/files/pdf-sample.pdf", visible: false, wait: 5)
end
click_link 'Description'
fill_in 'Title', with: etd[:title].first
fill_in 'Creator', with: etd[:creator].first
fill_in 'Keyword', with: etd[:keyword].first
# term for rights URI set in factory
select('No Known Copyright', from: 'Rights')

# give the browser time to enable button
sleep(2)
expect(find('#with_files_submit')).not_to be_disabled
click_on('Save')
sleep(5)
# wait until we have a record
persisted_etd = Etd.where(title: "Edited Title") while persisted_etd.nil?

click_on("pdf-sample.pdf")
accept_confirm { click_on("Delete This File") }
Expand Down
Binary file added spec/fixtures/.DS_Store
Binary file not shown.
34 changes: 16 additions & 18 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'capybara/poltergeist'

require 'database_cleaner'
require 'active_fedora/cleaner'
require 'hyrax/spec/factory_bot/build_strategies'
Expand All @@ -18,25 +18,16 @@
require 'selenium-webdriver'
require 'webmock/rspec'

# Capybara settings
poltergeist_options = {
js_errors: false,
timeout: 30,
logger: nil,
phantomjs_logger: StringIO.new,
phantomjs_options: [
'--load-images=no',
'--ignore-ssl-errors=yes'
]
}
Capybara.register_driver(:poltergeist) do |app|
Capybara::Poltergeist::Driver.new(app, poltergeist_options)
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.default_driver = :rack_test

Capybara.javascript_driver = :poltergeist
Capybara.javascript_driver = :selenium_chrome

Capybara.configure do |config|
config.default_max_wait_time = 10 # seconds
config.default_driver = :rack_test
end
# Support the old FactoryGirl name for the moment, use `FactoryBot` going
# forward.
FactoryGirl = FactoryBot unless defined?(FactoryGirl)
Expand Down Expand Up @@ -80,7 +71,7 @@
# config.filter_gems_from_backtrace("gem name")

config.include FactoryBot::Syntax::Methods

config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = false

config.before(:suite) do
Expand Down Expand Up @@ -114,6 +105,13 @@
DatabaseCleaner.clean
end

config.before(:each, type: :feature) do
# Note: Make browser huge so that no content is hidden during tests
Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[window-size=2500,2500] }
)
end

config.include(ControllerLevelHelpers, type: :view)
config.before(type: :view) { initialize_controller_helpers(view) }

Expand Down

0 comments on commit b345e61

Please sign in to comment.