@@ -0,0 +1,63 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.expand_path('../../test_helper', __FILE__) | |||
|
19 | require 'capybara/rails' | |||
|
20 | ||||
|
21 | Capybara.default_driver = :selenium | |||
|
22 | Capybara.register_driver :selenium do |app| | |||
|
23 | # Use the following driver definition to test locally using Chrome (also requires chromedriver to be in PATH) | |||
|
24 | # Capybara::Selenium::Driver.new(app, :browser => :chrome) | |||
|
25 | # Add :switches => %w[--lang=en] to force default browser locale to English | |||
|
26 | # Default for Selenium remote driver is to connect to local host on port 4444 | |||
|
27 | # This can be change using :url => 'http://localhost:9195' if necessary | |||
|
28 | # PhantomJS 1.8 now directly supports Webdriver Wire API, simply run it with `phantomjs --webdriver 4444` | |||
|
29 | # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) to run on Selenium Grid Hub with IE | |||
|
30 | Capybara::Selenium::Driver.new(app, :browser => :remote) | |||
|
31 | end | |||
|
32 | ||||
|
33 | module Redmine | |||
|
34 | module UiTest | |||
|
35 | # Base class for UI tests | |||
|
36 | class Base < ActionDispatch::IntegrationTest | |||
|
37 | include Capybara::DSL | |||
|
38 | ||||
|
39 | # Stop ActiveRecord from wrapping tests in transactions | |||
|
40 | # Transactional fixtures do not work with Selenium tests, because Capybara | |||
|
41 | # uses a separate server thread, which the transactions would be hidden | |||
|
42 | self.use_transactional_fixtures = false | |||
|
43 | ||||
|
44 | # Should not depend on locale since Redmine displays login page | |||
|
45 | # using default browser locale which depend on system locale for "real" browsers drivers | |||
|
46 | def log_user(login, password) | |||
|
47 | visit '/my/page' | |||
|
48 | assert_equal '/login', current_path | |||
|
49 | within('#login-form form') do | |||
|
50 | fill_in 'username', :with => login | |||
|
51 | fill_in 'password', :with => password | |||
|
52 | find('input[name=login]').click | |||
|
53 | end | |||
|
54 | assert_equal '/my/page', current_path | |||
|
55 | end | |||
|
56 | ||||
|
57 | teardown do | |||
|
58 | Capybara.reset_sessions! # Forget the (simulated) browser state | |||
|
59 | Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver | |||
|
60 | end | |||
|
61 | end | |||
|
62 | end | |||
|
63 | end |
@@ -0,0 +1,68 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.expand_path('../base', __FILE__) | |||
|
19 | ||||
|
20 | class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base | |||
|
21 | fixtures :projects, :users, :roles, :members, :member_roles, | |||
|
22 | :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues, | |||
|
23 | :enumerations, :custom_fields, :custom_values, :custom_fields_trackers | |||
|
24 | ||||
|
25 | # create an issue | |||
|
26 | def test_add_issue | |||
|
27 | log_user('jsmith', 'jsmith') | |||
|
28 | visit new_issue_path(:project_id => 1) | |||
|
29 | within('form#issue-form') do | |||
|
30 | select 'Bug', :from => 'Tracker' | |||
|
31 | select 'Low', :from => 'Priority' | |||
|
32 | fill_in 'Subject', :with => 'new test issue' | |||
|
33 | fill_in 'Description', :with => 'new issue' | |||
|
34 | select '0 %', :from => 'Done' | |||
|
35 | fill_in 'Due date', :with => '' | |||
|
36 | select '', :from => 'Assignee' | |||
|
37 | fill_in 'Searchable field', :with => 'Value for field 2' | |||
|
38 | # click_button 'Create' would match both 'Create' and 'Create and continue' buttons | |||
|
39 | find('input[name=commit]').click | |||
|
40 | end | |||
|
41 | ||||
|
42 | # find created issue | |||
|
43 | issue = Issue.find_by_subject("new test issue") | |||
|
44 | assert_kind_of Issue, issue | |||
|
45 | ||||
|
46 | # check redirection | |||
|
47 | find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created." | |||
|
48 | assert_equal issue_path(:id => issue), current_path | |||
|
49 | ||||
|
50 | # check issue attributes | |||
|
51 | assert_equal 'jsmith', issue.author.login | |||
|
52 | assert_equal 1, issue.project.id | |||
|
53 | assert_equal IssueStatus.find_by_name('New'), issue.status | |||
|
54 | assert_equal Tracker.find_by_name('Bug'), issue.tracker | |||
|
55 | assert_equal IssuePriority.find_by_name('Low'), issue.priority | |||
|
56 | assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field')) | |||
|
57 | end | |||
|
58 | ||||
|
59 | def test_preview_issue_description | |||
|
60 | log_user('jsmith', 'jsmith') | |||
|
61 | visit new_issue_path(:project_id => 1) | |||
|
62 | within('form#issue-form') do | |||
|
63 | fill_in 'Description', :with => 'new issue description' | |||
|
64 | click_link 'Preview' | |||
|
65 | end | |||
|
66 | find 'div#preview fieldset', :visible => true, :text => 'new issue description' | |||
|
67 | end | |||
|
68 | end |
@@ -80,6 +80,7 group :test do | |||||
80 | platforms << :jruby if defined?(JRUBY_VERSION) && JRUBY_VERSION >= "1.7" |
|
80 | platforms << :jruby if defined?(JRUBY_VERSION) && JRUBY_VERSION >= "1.7" | |
81 | gem "test-unit", :platforms => platforms |
|
81 | gem "test-unit", :platforms => platforms | |
82 | gem "mocha", "0.12.3" |
|
82 | gem "mocha", "0.12.3" | |
|
83 | gem 'capybara', '~> 2.0.0' | |||
83 | end |
|
84 | end | |
84 |
|
85 | |||
85 | local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") |
|
86 | local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") |
@@ -9,7 +9,7 Running Tests | |||||
9 |
|
9 | |||
10 | Run `rake --tasks test` to see available tests. |
|
10 | Run `rake --tasks test` to see available tests. | |
11 | Run `rake test` to run the entire test suite (except the tests for the |
|
11 | Run `rake test` to run the entire test suite (except the tests for the | |
12 | Apache perl module Redmine.pm, see below). |
|
12 | Apache perl module Redmine.pm and Capybara tests, see below). | |
13 |
|
13 | |||
14 | You can run `ruby test/unit/issue_test.rb` for running a single test case. |
|
14 | You can run `ruby test/unit/issue_test.rb` for running a single test case. | |
15 |
|
15 | |||
@@ -58,3 +58,12 Then, you can run the tests with: | |||||
58 |
|
58 | |||
59 | If you svn server is not running on localhost, you can use the REDMINE_TEST_DAV_SERVER |
|
59 | If you svn server is not running on localhost, you can use the REDMINE_TEST_DAV_SERVER | |
60 | environment variable to specify another host. |
|
60 | environment variable to specify another host. | |
|
61 | ||||
|
62 | Running Capybara tests | |||
|
63 | ====================== | |||
|
64 | ||||
|
65 | You need to have PhantomJS WebDriver listening on port 4444: | |||
|
66 | `phantomjs --webdriver 4444` | |||
|
67 | ||||
|
68 | Capybara tests can be run with: | |||
|
69 | `rake test:ui` |
@@ -100,4 +100,11 namespace :test do | |||||
100 | t.test_files = FileList['test/integration/routing/*_test.rb'] |
|
100 | t.test_files = FileList['test/integration/routing/*_test.rb'] | |
101 | end |
|
101 | end | |
102 | Rake::Task['test:rdm_routing'].comment = "Run the routing tests" |
|
102 | Rake::Task['test:rdm_routing'].comment = "Run the routing tests" | |
|
103 | ||||
|
104 | Rake::TestTask.new(:ui => "db:test:prepare") do |t| | |||
|
105 | t.libs << "test" | |||
|
106 | t.verbose = true | |||
|
107 | t.test_files = FileList['test/ui/**/*_test.rb'] | |||
|
108 | end | |||
|
109 | Rake::Task['test:ui'].comment = "Run the UI tests with Capybara (PhantomJS listening on port 4444 is required)" | |||
103 | end |
|
110 | end |
General Comments 0
You need to be logged in to leave comments.
Login now