3021: Clean up headless/selenium/javascript choices.
authorTom Clegg <tom@curoverse.com>
Sun, 4 Jan 2015 08:17:45 +0000 (03:17 -0500)
committerTom Clegg <tom@curoverse.com>
Sun, 4 Jan 2015 08:17:45 +0000 (03:17 -0500)
20 files changed:
apps/workbench/test/integration/application_layout_test.rb
apps/workbench/test/integration/collection_upload_test.rb
apps/workbench/test/integration/collections_test.rb
apps/workbench/test/integration/errors_test.rb
apps/workbench/test/integration/filterable_infinite_scroll_test.rb
apps/workbench/test/integration/jobs_test.rb
apps/workbench/test/integration/logins_test.rb
apps/workbench/test/integration/pipeline_instances_test.rb
apps/workbench/test/integration/pipeline_templates_test.rb
apps/workbench/test/integration/projects_test.rb
apps/workbench/test/integration/report_issue_test.rb
apps/workbench/test/integration/search_box_test.rb
apps/workbench/test/integration/smoke_test.rb
apps/workbench/test/integration/user_agreements_test.rb
apps/workbench/test/integration/user_manage_account_test.rb
apps/workbench/test/integration/user_profile_test.rb
apps/workbench/test/integration/users_test.rb
apps/workbench/test/integration/virtual_machines_test.rb
apps/workbench/test/integration/websockets_test.rb
apps/workbench/test/integration_helper.rb

index 6949072f71112c64bd66d281aff531b647aabe91..8a2906a43ac218c5a7a8e34fb54bbea48c388a2d 100644 (file)
@@ -7,7 +7,7 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
   reset_api_fixtures :after_suite, true
 
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   def verify_homepage user, invited, has_profile
index c4dc184acdd9f38423bbe1e4321009a41b538888..a2405765b0815fba1d631ec8dbe68e74309c656a 100644 (file)
@@ -1,10 +1,6 @@
 require 'integration_helper'
 
 class CollectionUploadTest < ActionDispatch::IntegrationTest
-  setup do
-    Headless.new.start
-  end
-
   setup do
     testfiles.each do |filename, content|
       open(testfile_path(filename), 'w') do |io|
@@ -20,7 +16,7 @@ class CollectionUploadTest < ActionDispatch::IntegrationTest
   end
 
   test "Create new collection using upload button" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token 'active', aproject_path
     find('.btn', text: 'Add data').click
     click_link 'Upload files from my computer'
@@ -32,15 +28,14 @@ class CollectionUploadTest < ActionDispatch::IntegrationTest
   end
 
   test "No Upload tab on non-writable collection" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit(page_with_token 'active',
           '/collections/'+api_fixture('collections')['user_agreement']['uuid'])
     assert_no_selector '.nav-tabs Upload'
   end
 
   test "Upload two empty files with the same name" do
-    # Selenium is needed because poltergeist/phantomjs can't do file uploads.
-    Capybara.current_driver = :selenium
+    need_selenium "to make file uploads work"
     visit page_with_token 'active', sandbox_path
     find('.nav-tabs a', text: 'Upload').click
     attach_file 'file_selector', testfile_path('empty.txt')
@@ -54,8 +49,7 @@ class CollectionUploadTest < ActionDispatch::IntegrationTest
   end
 
   test "Upload non-empty files, report errors" do
-    # Selenium is needed because poltergeist/phantomjs can't do file uploads.
-    Capybara.current_driver = :selenium
+    need_selenium "to make file uploads work"
     visit page_with_token 'active', sandbox_path
     find('.nav-tabs a', text: 'Upload').click
     attach_file 'file_selector', testfile_path('a')
index 6999b1bb928654f21c7ee1670ab458c074de98a3..4338d19ea1fa5a61f6244dadb674e5feb6e35c97 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class CollectionsTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   # check_checkboxes_state asserts that the page holds at least one
index 19ed7dca684f8b1a460e560220fc82a642fc687d..03c359e089590f20f8ea12334b7d518923923479 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class ErrorsTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   BAD_UUID = "ffffffffffffffffffffffffffffffff+0"
index 90b73d5e9cd4695ed39e4b6a4d8221cae19de73c..b4dadcd13f853f2086cb62797d1e12a67da3105d 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class FilterableInfiniteScrollTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   # Chrome remembers what you had in the text field when you hit
index d1f5e780932fcaab959bf07ad486c07aefc68edc..716e7319874d56189b145acae6fd4c137a590f23 100644 (file)
@@ -14,7 +14,7 @@ class JobsTest < ActionDispatch::IntegrationTest
   end
 
   test "add job description" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token("active", "/jobs")
 
     # go to job running the script "doesnotexist"
@@ -39,7 +39,7 @@ class JobsTest < ActionDispatch::IntegrationTest
   end
 
   test "view job log" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     job = api_fixture('jobs')['job_with_real_log']
 
     IO.expects(:popen).returns(fakepipe_with_log_data)
@@ -58,7 +58,7 @@ class JobsTest < ActionDispatch::IntegrationTest
   end
 
   test 'view partial job log' do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     # This config will be restored during teardown by ../test_helper.rb:
     Rails.configuration.log_viewer_max_bytes = 100
 
index 9d4e04bfee5f4cee67638c607f2cc1ddcd7d902a..2e2de70318e7aa84c2c2e92d0526d2a99424a38b 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class LoginsTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   test "login with api_token works after redirect" do
index 313bde64ec2b223d594f993ede632158ad60b31d..e16cf72d942179f6274da2522a8002a2702fb530 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class PipelineInstancesTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   test 'Create and run a pipeline' do
index b909ac0378da9497beab2fda4783cd3e138c73f8..19a51095de3c50569c12c111e5ff5e1dda7cf480 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class PipelineTemplatesTest < ActionDispatch::IntegrationTest
   test "JSON popup available for strange components" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     uuid = api_fixture("pipeline_templates")["components_is_jobspec"]["uuid"]
     visit page_with_token("active", "/pipeline_templates/#{uuid}")
     click_on "Components"
@@ -14,7 +14,7 @@ class PipelineTemplatesTest < ActionDispatch::IntegrationTest
   end
 
   test "pipeline template description" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token("active", "/pipeline_templates")
 
     # go to Two Part pipeline template
index 04f99c493aced7371efd53c9dafc0fc9cc2f0f5c..45fa3929b2f338c83353c1ca4a17a11a713d9570 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class ProjectsTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   test 'Check collection count for A Project in the tab pane titles' do
index 7d050f43537680da5b44a166b6901a40cea4baec..7d4058db4a974126625af8d1648680924b8f9a4f 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class ReportIssueTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     @user_profile_form_fields = Rails.configuration.user_profile_form_fields
   end
 
index 958baf749b0fb57c1d0e95f27d477f15334b99f2..05c7f25185f92a4bba3aafc9d820f49bd0f9d26b 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class SearchBoxTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   # test the search box
index 1e3337044738cf3bca873d1545c96c850f636df0..a626e242843262643768afdfbbd3ca813c698d8c 100644 (file)
@@ -3,7 +3,7 @@ require 'uri'
 
 class SmokeTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   def assert_visit_success(allowed=[200])
index dbd395094466034ee84dc84c747214fa7c27c7aa..16b320885e61bac7ee1e5d21bf1a75a22fc7345c 100644 (file)
@@ -3,7 +3,7 @@ require 'integration_helper'
 class UserAgreementsTest < ActionDispatch::IntegrationTest
 
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   def continuebutton_selector
index 664bf991b6bd1b0019efd1395808cd3a967b5f73..fae7e62e728d12212dd4f2c3cb69dcbe420f83d2 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class UserManageAccountTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
   end
 
   # test manage_account page
index 1caa5719dbac9fbe4d105d3d85c7d1163228e2b9..cbd591a38dcc69ff60f0340cc2d736ea3f01dd00 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class UserProfileTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     @user_profile_form_fields = Rails.configuration.user_profile_form_fields
   end
 
index 5975395ed2b28b38f636550c5e71fc2937b8aad4..4a45a6a87c143ebfc3914864581390f3ee4a0061 100644 (file)
@@ -3,14 +3,14 @@ require 'integration_helper'
 class UsersTest < ActionDispatch::IntegrationTest
 
   test "login as active user but not admin" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token('active_trustedclient')
 
     assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
   end
 
   test "login as admin user and verify active user data" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token('admin_trustedclient')
 
     # go to Users list page
@@ -42,7 +42,7 @@ class UsersTest < ActionDispatch::IntegrationTest
   end
 
   test "create a new user" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
 
     visit page_with_token('admin_trustedclient')
 
@@ -86,7 +86,7 @@ class UsersTest < ActionDispatch::IntegrationTest
   end
 
   test "setup the active user" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token('admin_trustedclient')
 
     find('#system-menu').click
@@ -138,7 +138,7 @@ class UsersTest < ActionDispatch::IntegrationTest
   end
 
   test "unsetup active user" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
 
     visit page_with_token('admin_trustedclient')
 
index 28763da0876b14d8698f5e4478ac2f98508d7258..1d398a595ce854335df8e3c1d5a434632ed89728 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class VirtualMachinesTest < ActionDispatch::IntegrationTest
   test "make and name a new virtual machine" do
-    Capybara.current_driver = Capybara.javascript_driver
+    need_javascript
     visit page_with_token('admin_trustedclient')
     find('#system-menu').click
     click_link 'Virtual machines'
index 6eb4d458a9f8b38ea9012a4249562a1fb150d0ca..efc2539e7070d14efbd1c25c79a8838398bdd518 100644 (file)
@@ -2,7 +2,7 @@ require 'integration_helper'
 
 class WebsocketTest < ActionDispatch::IntegrationTest
   setup do
-    Capybara.current_driver = :selenium
+    need_selenium "to make websockets work"
   end
 
   test "test page" do
index 01e3ff88645f846af2cab5cdfb9056407ee85aa1..e0b82e5847326a31e21cc6918af48e82d36ddbf0 100644 (file)
@@ -81,4 +81,24 @@ class ActionDispatch::IntegrationTest
     end
     Capybara.reset_sessions!
   end
+
+  Capybara.default_driver = :rack_test
+
+  setup do
+    Capybara.use_default_driver
+  end
+
+  def need_selenium reason=nil
+    Capybara.current_driver = :selenium
+    unless ENV['ARVADOS_TEST_HEADFUL'] or @headless
+      @headless = Headless.new(display: 101, reuse: true)
+      @headless.start
+    end
+  end
+
+  def need_javascript reason=nil
+    unless Capybara.current_driver == :selenium
+      Capybara.current_driver = :poltergeist
+    end
+  end
 end