##// END OF EJS Templates
shorten comment lines at test/ui/base.rb...
Toshi MARUYAMA -
r11745:9b549fdfe92c
parent child
Show More
@@ -1,69 +1,72
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'capybara/rails'
19 require 'capybara/rails'
20
20
21 Capybara.default_driver = :selenium
21 Capybara.default_driver = :selenium
22 Capybara.register_driver :selenium do |app|
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)
23 # Use the following driver definition to test locally using Chrome
24 # (also requires chromedriver to be in PATH)
24 # Capybara::Selenium::Driver.new(app, :browser => :chrome)
25 # Capybara::Selenium::Driver.new(app, :browser => :chrome)
25 # Add :switches => %w[--lang=en] to force default browser locale to English
26 # 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 # 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 # 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 # PhantomJS 1.8 now directly supports Webdriver Wire API,
29 # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) to run on Selenium Grid Hub with IE
30 # simply run it with `phantomjs --webdriver 4444`
31 # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer)
32 # to run on Selenium Grid Hub with IE
30 Capybara::Selenium::Driver.new(app, :browser => :remote)
33 Capybara::Selenium::Driver.new(app, :browser => :remote)
31 end
34 end
32
35
33 DatabaseCleaner.strategy = :truncation
36 DatabaseCleaner.strategy = :truncation
34
37
35 module Redmine
38 module Redmine
36 module UiTest
39 module UiTest
37 # Base class for UI tests
40 # Base class for UI tests
38 class Base < ActionDispatch::IntegrationTest
41 class Base < ActionDispatch::IntegrationTest
39 include Capybara::DSL
42 include Capybara::DSL
40
43
41 # Stop ActiveRecord from wrapping tests in transactions
44 # Stop ActiveRecord from wrapping tests in transactions
42 # Transactional fixtures do not work with Selenium tests, because Capybara
45 # Transactional fixtures do not work with Selenium tests, because Capybara
43 # uses a separate server thread, which the transactions would be hidden
46 # uses a separate server thread, which the transactions would be hidden
44 self.use_transactional_fixtures = false
47 self.use_transactional_fixtures = false
45
48
46 # default: 2
49 # default: 2
47 Capybara.default_wait_time = 7
50 Capybara.default_wait_time = 7
48
51
49 # Should not depend on locale since Redmine displays login page
52 # Should not depend on locale since Redmine displays login page
50 # using default browser locale which depend on system locale for "real" browsers drivers
53 # using default browser locale which depend on system locale for "real" browsers drivers
51 def log_user(login, password)
54 def log_user(login, password)
52 visit '/my/page'
55 visit '/my/page'
53 assert_equal '/login', current_path
56 assert_equal '/login', current_path
54 within('#login-form form') do
57 within('#login-form form') do
55 fill_in 'username', :with => login
58 fill_in 'username', :with => login
56 fill_in 'password', :with => password
59 fill_in 'password', :with => password
57 find('input[name=login]').click
60 find('input[name=login]').click
58 end
61 end
59 assert_equal '/my/page', current_path
62 assert_equal '/my/page', current_path
60 end
63 end
61
64
62 teardown do
65 teardown do
63 Capybara.reset_sessions! # Forget the (simulated) browser state
66 Capybara.reset_sessions! # Forget the (simulated) browser state
64 Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
67 Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
65 DatabaseCleaner.clean
68 DatabaseCleaner.clean
66 end
69 end
67 end
70 end
68 end
71 end
69 end
72 end
General Comments 0
You need to be logged in to leave comments. Login now