Files
openfoodnetwork/spec/system/support/capybara_setup.rb
Maikel Linke 3f98e2e559 Reduce Capybara wait time during development
In test-driven development, you run tests and expect them to fail.
Waiting for the results unnecessarily long just slows down development.

And even though CI can be slow, we should aim for good performance of
our code. Long wait times can hide performance bottle necks.

If anyone struggles with the default value, we can add an environment
variable to adjust the wait time to your machine in .env.test.local. But
this may just work for everyone.
2024-02-15 13:11:51 +11:00

30 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# Whether fields, links, and buttons will match against aria-label attribute.
# This allows us to find <input aria-label="Name"> with `expect(page).to have_field "Name"`
Capybara.enable_aria_label = true
# The default wait time is 2 seconds. Small is good for test-driven development
# ensuring efficient code but CI can be a bit slow. We want to avoid flakiness.
Capybara.default_max_wait_time = 10 if ENV["CI"]
# Normalize whitespaces when using `has_text?` and similar matchers,
# i.e., ignore newlines, trailing spaces, etc.
# That makes tests less dependent on slightly UI changes.
Capybara.default_normalize_ws = true
# Where to store system tests artifacts (e.g. screenshots, downloaded files, etc.).
# It could be useful to be able to configure this path from the outside (e.g., on CI).
Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")
Capybara.singleton_class.prepend(Module.new do
attr_accessor :last_used_session
def using_session(name, &)
self.last_used_session = name
super
ensure
self.last_used_session = nil
end
end)