From: Jean-Philippe Lang Date: Sat, 8 Jul 2017 12:47:14 +0000 (+0000) Subject: Adds a UI test for #26364. X-Git-Tag: 4.0.0~648 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e0181ee894a0f800cdf4b2e85b784db1e177118c;p=redmine.git Adds a UI test for #26364. git-svn-id: http://svn.redmine.org/redmine/trunk@16769 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/doc/RUNNING_TESTS b/doc/RUNNING_TESTS index 039198fa0..91a534aa0 100644 --- a/doc/RUNNING_TESTS +++ b/doc/RUNNING_TESTS @@ -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` diff --git a/test/ui/base.rb b/test/ui/base.rb index fde2a6314..53c2e7755 100644 --- a/test/ui/base.rb +++ b/test/ui/base.rb @@ -17,21 +17,52 @@ 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 diff --git a/test/ui/issues_test_ui.rb b/test/ui/issues_test_ui.rb index 27d6af586..3227024f4 100644 --- a/test/ui/issues_test_ui.rb +++ b/test/ui/issues_test_ui.rb @@ -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