selenium_driver.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # This file registers the custom Zammad chrome and firefox drivers.
  2. # The options check if a REMOTE_URL ENV is given and change the
  3. # configurations accordingly.
  4. Capybara.register_driver(:zammad_chrome) do |app|
  5. # Turn on browser logs
  6. capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  7. loggingPrefs: {
  8. browser: 'ALL'
  9. },
  10. chromeOptions: {
  11. prefs: {
  12. 'intl.accept_languages' => 'en-US',
  13. 'profile.default_content_setting_values.notifications' => 1, # ALLOW notifications
  14. },
  15. },
  16. )
  17. options = {
  18. browser: :chrome,
  19. desired_capabilities: capabilities,
  20. }
  21. if ENV['REMOTE_URL'].present?
  22. options[:browser] = :remote
  23. options[:url] = ENV['REMOTE_URL']
  24. end
  25. Capybara::Selenium::Driver.new(app, options)
  26. end
  27. Capybara.register_driver(:zammad_firefox) do |app|
  28. profile = Selenium::WebDriver::Firefox::Profile.new
  29. profile['intl.locale.matchOS'] = false
  30. profile['intl.accept_languages'] = 'en-US'
  31. profile['general.useragent.locale'] = 'en-US'
  32. profile['permissions.default.desktop-notification'] = 1 # ALLOW notifications
  33. capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(
  34. firefox_profile: profile,
  35. )
  36. options = {
  37. browser: :firefox,
  38. desired_capabilities: capabilities,
  39. }
  40. if ENV['REMOTE_URL'].present?
  41. options[:browser] = :remote
  42. options[:url] = ENV['REMOTE_URL']
  43. end
  44. Capybara::Selenium::Driver.new(app, options)
  45. end