window_actions.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. module WindowActions
  3. delegate :app_host, to: Capybara
  4. # This is a convenient wrapper method around #switch_to_window
  5. # which switch to an given window index if exists.
  6. #
  7. # @example
  8. # switch_to_window_index(2)
  9. # => switch to window index 2
  10. #
  11. def switch_to_window_index(index)
  12. return false if !windows[index - 1]
  13. switch_to_window(windows[index - 1])
  14. end
  15. # This is a convenient wrapper method around #close window
  16. # which will close the given window index if it exists.
  17. # If only one window is still open afterwards it will switch to it.
  18. #
  19. # @example
  20. # close_window_index(2)
  21. # => close window with index 2
  22. #
  23. def close_window_index(index)
  24. return false if !windows[index - 1]
  25. windows[index - 1].close
  26. switch_to_window(windows[0]) if windows.length == 1
  27. end
  28. # This is a convenient wrapper method around #open_new_window
  29. # which open a new window and switched directly to it
  30. #
  31. # @example
  32. # open_window_and_switch
  33. # => open new window and switch to this window
  34. #
  35. def open_window_and_switch
  36. window = open_new_window
  37. switch_to_window(window)
  38. end
  39. end
  40. RSpec.configure do |config|
  41. config.include WindowActions, type: :system
  42. end