2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
require_relative './set_up'
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2022-06-09 04:20:41 +00:00
|
|
|
capybara_examples_performed = 0
|
|
|
|
|
2022-03-02 09:35:35 +00:00
|
|
|
config.before(:each, type: :system) do |example|
|
2018-12-19 14:47:15 +00:00
|
|
|
|
2020-12-10 09:17:26 +00:00
|
|
|
Capybara.register_server :puma_wrapper do |app, port, host, **_options|
|
|
|
|
|
|
|
|
# update fqdn Setting according to random assigned Rack server port
|
|
|
|
Setting.set('fqdn', "#{host}:#{port}")
|
|
|
|
|
|
|
|
# start a silenced Puma as application server
|
2021-07-06 07:52:22 +00:00
|
|
|
Capybara.servers[:puma].call(app, port, host, Silent: true, Host: '0.0.0.0', Threads: '0:16')
|
2020-12-10 09:17:26 +00:00
|
|
|
end
|
|
|
|
Capybara.server = :puma_wrapper
|
2018-12-19 14:47:15 +00:00
|
|
|
|
|
|
|
# set the Host from gather container IP for CI runs
|
|
|
|
if ENV['CI'].present?
|
|
|
|
ip_address = Socket.ip_address_list.detect(&:ipv4_private?).ip_address
|
|
|
|
host!("http://#{ip_address}")
|
|
|
|
end
|
|
|
|
|
|
|
|
# set custom Zammad driver (e.g. zammad_chrome) for special
|
|
|
|
# functionalities and CI requirements
|
2022-03-02 09:35:35 +00:00
|
|
|
browser_name = ENV.fetch('BROWSER', 'firefox')
|
|
|
|
driven_by(:"zammad_#{browser_name}")
|
|
|
|
|
|
|
|
case example.metadata.fetch(:screen_size, :desktop)
|
|
|
|
when :tablet
|
|
|
|
browser_width = 1020
|
|
|
|
browser_height = 760
|
|
|
|
else # :desktop
|
|
|
|
browser_width = 1520
|
|
|
|
browser_height = 1000
|
|
|
|
end
|
|
|
|
|
2020-12-15 11:29:07 +00:00
|
|
|
page.driver.browser.manage.window.resize_to(browser_width, browser_height)
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
2022-03-04 13:49:17 +00:00
|
|
|
|
|
|
|
config.after(:each, type: :system) do
|
2022-06-09 04:20:41 +00:00
|
|
|
capybara_examples_performed += 1
|
|
|
|
# End the main capybara session only from time to time, to speed up tests and make
|
|
|
|
# sure memory consumption does not rise too much.
|
2022-03-04 13:49:17 +00:00
|
|
|
# Make sure additional sessions (from using_sessions) are always ended
|
|
|
|
# after every test and not kept alive. Selenium will automatically close
|
|
|
|
# idle sessions which can cause 404 errors later.
|
|
|
|
# (see https://github.com/teamcapybara/capybara/issues/2237)
|
|
|
|
Capybara.send(:session_pool).reverse_each do |_mode, session|
|
2022-06-09 04:20:41 +00:00
|
|
|
if !session.eql?(Capybara.current_session) || (capybara_examples_performed % 100).zero?
|
2022-03-04 13:49:17 +00:00
|
|
|
session.quit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-01 08:53:08 +00:00
|
|
|
config.around(:each, type: :system) do |example|
|
2022-04-22 14:40:18 +00:00
|
|
|
use_vcr = example.metadata.fetch(:use_vcr, false)
|
|
|
|
|
2022-04-01 08:53:08 +00:00
|
|
|
# WebMock makes it impossible to have persistent http connections to Selenium,
|
|
|
|
# which may cause overhead and Net::OpenTimeout errors.
|
2022-04-22 14:40:18 +00:00
|
|
|
WebMock.disable! if !use_vcr
|
2022-04-12 05:41:23 +00:00
|
|
|
# rspec-retry
|
|
|
|
example.run_with_retry retry: 3, exceptions_to_retry: [Net::OpenTimeout, Net::ReadTimeout]
|
2022-04-22 14:40:18 +00:00
|
|
|
WebMock.enable! if !use_vcr
|
2022-04-01 08:53:08 +00:00
|
|
|
end
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|