You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application_system_test_case.rb 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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. require File.expand_path('../test_helper', __FILE__)
  18. class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  19. DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
  20. driven_by :selenium, using: :chrome, screen_size: [1024, 900], options: {
  21. desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
  22. 'chromeOptions' => {
  23. 'prefs' => {
  24. 'download.default_directory' => DOWNLOADS_PATH,
  25. 'download.prompt_for_download' => false,
  26. 'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
  27. }
  28. }
  29. )
  30. }
  31. setup do
  32. clear_downloaded_files
  33. Setting.delete_all
  34. Setting.clear_cache
  35. end
  36. teardown do
  37. Setting.delete_all
  38. Setting.clear_cache
  39. end
  40. # Should not depend on locale since Redmine displays login page
  41. # using default browser locale which depend on system locale for "real" browsers drivers
  42. def log_user(login, password)
  43. visit '/my/page'
  44. assert_equal '/login', current_path
  45. within('#login-form form') do
  46. fill_in 'username', :with => login
  47. fill_in 'password', :with => password
  48. find('input[name=login]').click
  49. end
  50. assert_equal '/my/page', current_path
  51. end
  52. def clear_downloaded_files
  53. FileUtils.rm downloaded_files
  54. end
  55. def downloaded_files
  56. Dir.glob("#{DOWNLOADS_PATH}/*").reject {|f| f=~/crdownload$/}
  57. end
  58. # Returns the path of the download file
  59. def downloaded_file
  60. Timeout.timeout(5) do
  61. while downloaded_files.empty?
  62. sleep 0.2
  63. end
  64. end
  65. downloaded_files.first
  66. end
  67. end
  68. FileUtils.mkdir_p ApplicationSystemTestCase::DOWNLOADS_PATH