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.
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`
......@@ -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
......
......@@ -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
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