Commit 5d4239cc authored by jplang's avatar jplang

Adds a UI test for #26364.

git-svn-id: https://svn.redmine.org/redmine/trunk@16769 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 1fb1d845
...@@ -66,8 +66,8 @@ REDMINE_TEST_DAV_SERVER environment variable to specify another host. ...@@ -66,8 +66,8 @@ REDMINE_TEST_DAV_SERVER environment variable to specify another host.
Running Capybara tests Running Capybara tests
====================== ======================
You need to have PhantomJS WebDriver listening on port 4444: You need to have ChromeDriver installed and available in your PATH:
`phantomjs --webdriver 4444` https://sites.google.com/a/chromium.org/chromedriver/
Capybara tests can be run with: Capybara tests can be run with:
`rake test:ui` `rake test:ui`
...@@ -17,21 +17,52 @@ ...@@ -17,21 +17,52 @@
require File.expand_path('../../test_helper', __FILE__) require File.expand_path('../../test_helper', __FILE__)
require 'capybara/rails' require 'capybara/rails'
require 'fileutils'
require 'timeout'
Capybara.default_driver = :selenium module Redmine
Capybara.register_driver :selenium do |app| module UiTest
# Use the following driver definition to test locally using Chrome module Downloads
# (also requires chromedriver to be in PATH) DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
# Capybara::Selenium::Driver.new(app, :browser => :chrome)
# Add :switches => %w[--lang=en] to force default browser locale to English def clear_downloaded_files
# Default for Selenium remote driver is to connect to local host on port 4444 FileUtils.rm downloaded_files
# This can be change using :url => 'http://localhost:9195' if necessary end
# PhantomJS 1.8 now directly supports Webdriver Wire API,
# simply run it with `phantomjs --webdriver 4444` def downloaded_files
# Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) Dir.glob("#{DOWNLOADS_PATH}/*").reject {|f| f=~/crdownload$/}
# to run on Selenium Grid Hub with IE end
Capybara::Selenium::Driver.new(app, :browser => :remote)
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 end
Capybara.default_driver = :chrome
# default: 2 # default: 2
Capybara.default_wait_time = 2 Capybara.default_wait_time = 2
...@@ -41,6 +72,7 @@ module Redmine ...@@ -41,6 +72,7 @@ module Redmine
# Base class for UI tests # Base class for UI tests
class Base < ActionDispatch::IntegrationTest class Base < ActionDispatch::IntegrationTest
include Capybara::DSL include Capybara::DSL
include Redmine::UiTest::Downloads
# Stop ActiveRecord from wrapping tests in transactions # Stop ActiveRecord from wrapping tests in transactions
# Transactional fixtures do not work with Selenium tests, because Capybara # Transactional fixtures do not work with Selenium tests, because Capybara
...@@ -61,8 +93,7 @@ module Redmine ...@@ -61,8 +93,7 @@ module Redmine
end end
setup do setup do
# Set the page width higher than 900 to get the full layout with sidebar clear_downloaded_files
page.driver.browser.manage.window.resize_to(1024, 900)
end end
teardown do teardown do
......
...@@ -332,4 +332,19 @@ class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base ...@@ -332,4 +332,19 @@ class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
sleep 1 sleep 1
assert_equal 'Updated notes', Journal.find(2).notes assert_equal 'Updated notes', Journal.find(2).notes
end 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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment