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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. FileUtils.rm downloaded_files
  55. end
  56. def downloaded_files
  57. Dir.glob("#{DOWNLOADS_PATH}/*").reject {|f| f=~/\.(tmp|crdownload)$/}
  58. end
  59. # Returns the path of the download file
  60. def downloaded_file
  61. Timeout.timeout(5) do
  62. while downloaded_files.empty?
  63. sleep 0.2
  64. end
  65. end
  66. downloaded_files.first
  67. end
  68. end
  69. FileUtils.mkdir_p ApplicationSystemTestCase::DOWNLOADS_PATH