]> source.dussan.org Git - redmine.git/commitdiff
Adds a UI test for #26364.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 8 Jul 2017 12:47:14 +0000 (12:47 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 8 Jul 2017 12:47:14 +0000 (12:47 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16769 e93f8b46-1217-0410-a6f0-8f06a7374b81

doc/RUNNING_TESTS
test/ui/base.rb
test/ui/issues_test_ui.rb

index 039198fa0fa01fa5da18a7a268525d6861e47a91..91a534aa0a76c7b2a1753873d93ff8cc4a5c110a 100644 (file)
@@ -66,8 +66,8 @@ REDMINE_TEST_DAV_SERVER environment variable to specify another host.
 Running Capybara tests
 ======================
 
-You need to have PhantomJS WebDriver listening on port 4444:
-`phantomjs --webdriver 4444`
+You need to have ChromeDriver installed and available in your PATH:
+https://sites.google.com/a/chromium.org/chromedriver/
 
 Capybara tests can be run with:
 `rake test:ui`
index fde2a63147cf8264449767f656df7af0410e3642..53c2e775510d8dccb459ef55520137ce8a0aa513 100644 (file)
 
 require File.expand_path('../../test_helper', __FILE__)
 require 'capybara/rails'
+require 'fileutils'
+require 'timeout'
 
-Capybara.default_driver = :selenium
-Capybara.register_driver :selenium do |app|
-  # Use the following driver definition to test locally using Chrome
-  # (also requires chromedriver to be in PATH)
-  # Capybara::Selenium::Driver.new(app, :browser => :chrome)
-  # Add :switches => %w[--lang=en] to force default browser locale to English
-  # Default for Selenium remote driver is to connect to local host on port 4444 
-  # This can be change using :url => 'http://localhost:9195' if necessary
-  # PhantomJS 1.8 now directly supports Webdriver Wire API,
-  # simply run it with `phantomjs --webdriver 4444`
-  # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer)
-  # to run on Selenium Grid Hub with IE
-  Capybara::Selenium::Driver.new(app, :browser => :remote)
+module Redmine
+  module UiTest
+    module Downloads
+      DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
+
+      def clear_downloaded_files
+        FileUtils.rm downloaded_files
+      end
+
+      def downloaded_files
+        Dir.glob("#{DOWNLOADS_PATH}/*").reject {|f| f=~/crdownload$/}
+      end
+
+      def downloaded_file
+        Timeout.timeout(5) do
+          while downloaded_files.empty?
+            sleep 0.2
+          end
+        end
+        downloaded_files.first
+      end
+    end
+  end
+end
+
+FileUtils.mkdir_p Redmine::UiTest::Downloads::DOWNLOADS_PATH
+
+Capybara.register_driver :chrome do |app|
+  Capybara::Selenium::Driver.new(app,
+      :browser => :chrome,
+      :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(
+        'chromeOptions' => {
+          'args' => [ "--window-size=1024,900" ],
+          'prefs' => {
+            'download.default_directory' => Redmine::UiTest::Downloads::DOWNLOADS_PATH,
+            'download.prompt_for_download' => false,
+            'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
+          }
+        }
+      )
+    )
 end
+Capybara.default_driver = :chrome
 
 # default: 2
 Capybara.default_wait_time = 2
@@ -41,6 +72,7 @@ module Redmine
     # Base class for UI tests
     class Base < ActionDispatch::IntegrationTest
       include Capybara::DSL
+      include Redmine::UiTest::Downloads
 
       # Stop ActiveRecord from wrapping tests in transactions
       # Transactional fixtures do not work with Selenium tests, because Capybara
@@ -61,8 +93,7 @@ module Redmine
       end
 
       setup do
-        # Set the page width higher than 900 to get the full layout with sidebar
-        page.driver.browser.manage.window.resize_to(1024, 900)
+        clear_downloaded_files
       end
 
       teardown do
index 27d6af586c7c8e4760eb4bd21a36aef1301047b2..3227024f4a5b73d9e566a37d56740d63329781ff 100644 (file)
@@ -332,4 +332,19 @@ class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
     sleep 1
     assert_equal 'Updated notes', Journal.find(2).notes
   end
+
+  def test_index_as_csv_should_reflect_sort
+    log_user('admin', 'admin')
+
+    visit '/issues'
+    # Sort issues by subject
+    click_on 'Subject'
+    click_on 'CSV'
+    click_on 'Export'
+
+    csv = CSV.read(downloaded_file)
+    subject_index = csv.shift.index('Subject')
+    subjects = csv.map {|row| row[subject_index]}
+    assert_equal subjects.sort, subjects
+  end
 end