Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

application_system_test_case.rb 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../test_helper', __FILE__)
  19. class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  20. DOWNLOADS_PATH = File.expand_path(File.join(Rails.root, 'tmp', 'downloads'))
  21. driven_by :selenium, using: :chrome, screen_size: [1024, 900], options: {
  22. desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(
  23. 'chromeOptions' => {
  24. 'prefs' => {
  25. 'download.default_directory' => DOWNLOADS_PATH,
  26. 'download.prompt_for_download' => false,
  27. 'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
  28. }
  29. }
  30. )
  31. }
  32. setup do
  33. clear_downloaded_files
  34. Setting.delete_all
  35. Setting.clear_cache
  36. end
  37. teardown do
  38. Setting.delete_all
  39. Setting.clear_cache
  40. end
  41. # Should not depend on locale since Redmine displays login page
  42. # using default browser locale which depend on system locale for "real" browsers drivers
  43. def log_user(login, password)
  44. visit '/my/page'
  45. assert_equal '/login', current_path
  46. within('#login-form form') do
  47. fill_in 'username', :with => login
  48. fill_in 'password', :with => password
  49. find('input[name=login]').click
  50. end
  51. assert_equal '/my/page', current_path
  52. end
  53. def clear_downloaded_files
  54. # https://github.com/SeleniumHQ/selenium/issues/5292
  55. FileUtils.rm downloaded_files if Redmine::Platform.mswin?
  56. end
  57. def downloaded_files(filename='*')
  58. # https://github.com/SeleniumHQ/selenium/issues/5292
  59. downloaded_path = Redmine::Platform.mswin? ? DOWNLOADS_PATH : "#{ENV['HOME']}/Downloads"
  60. Dir.glob("#{downloaded_path}/#{filename}").
  61. reject{|f| f=~/\.(tmp|crdownload)$/}.sort_by{|f| File.mtime(f)}
  62. end
  63. # Returns the path of the download file
  64. def downloaded_file(filename='*')
  65. files = []
  66. Timeout.timeout(5) do
  67. loop do
  68. files = downloaded_files(filename)
  69. break if files.present?
  70. sleep 0.2
  71. end
  72. end
  73. files.last
  74. end
  75. end
  76. FileUtils.mkdir_p ApplicationSystemTestCase::DOWNLOADS_PATH