Maintenance: Add support for visit-ing external URLs in Capybara system tests.
This commit is contained in:
parent
c3b1b4413f
commit
161dd525ac
2 changed files with 26 additions and 4 deletions
|
@ -90,26 +90,47 @@ module CommonActions
|
||||||
visit('logout')
|
visit('logout')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overwrites the Capybara::Session#visit method to allow SPA navigation.
|
# Overwrites the Capybara::Session#visit method to allow SPA navigation
|
||||||
|
# and visiting of external URLs.
|
||||||
# All routes not starting with `/` will be handled as SPA routes.
|
# All routes not starting with `/` will be handled as SPA routes.
|
||||||
|
# All routes containing `://` will be handled as an external URL.
|
||||||
#
|
#
|
||||||
# @see Capybara::Session#visit
|
# @see Capybara::Session#visit
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# visit('logout')
|
# visit('logout')
|
||||||
# => visited SPA route '/#logout'
|
# => visited SPA route 'localhost:32435/#logout'
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# visit('/test/ui')
|
# visit('/test/ui')
|
||||||
# => visited regular route '/test/ui'
|
# => visited regular route 'localhost:32435/test/ui'
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# visit('https://zammad.org')
|
||||||
|
# => visited external URL 'https://zammad.org'
|
||||||
#
|
#
|
||||||
def visit(route)
|
def visit(route)
|
||||||
if !route.start_with?('/')
|
if route.include?('://')
|
||||||
|
return without_port do
|
||||||
|
super(route)
|
||||||
|
end
|
||||||
|
elsif !route.start_with?('/')
|
||||||
route = "/##{route}"
|
route = "/##{route}"
|
||||||
end
|
end
|
||||||
super(route)
|
super(route)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Overwrites the global Capybara.always_include_port setting (true)
|
||||||
|
# with false. This comes in handy when visiting external pages.
|
||||||
|
#
|
||||||
|
def without_port
|
||||||
|
original = Capybara.current_session.config.always_include_port
|
||||||
|
Capybara.current_session.config.always_include_port = false
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Capybara.current_session.config.always_include_port = original
|
||||||
|
end
|
||||||
|
|
||||||
# This method is equivalent to Capybara::RSpecMatchers#have_current_path
|
# This method is equivalent to Capybara::RSpecMatchers#have_current_path
|
||||||
# but checks the SPA route instead of the actual path.
|
# but checks the SPA route instead of the actual path.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Capybara.configure do |config|
|
Capybara.configure do |config|
|
||||||
|
config.threadsafe = true
|
||||||
config.always_include_port = true
|
config.always_include_port = true
|
||||||
config.default_max_wait_time = 16
|
config.default_max_wait_time = 16
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue