module Nav
Simple helper that makes navigating using the config file easier It will check if a given string is a URL or a config value and goto that page accordingly
Public Class Methods
get_url(page)
click to toggle source
Loads the URL from the config, prioritized from top to bottom: production.pages.home production.pages.home.path pages.home pages.home.path
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb, line 27 def get_url page begin return env_or_config("pages.#{page}") rescue RuntimeError return env_or_config("pages.#{page}.path") end end
is_url?(string)
click to toggle source
Confirms if the given URL is a valid URL
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb, line 36 def is_url? string uri = URI.parse(string) %w( http https ).include?(uri.scheme) rescue URI::BadURIError false rescue URI::InvalidURIError false end
set_url(config_page_or_url)
click to toggle source
returns the expected URL
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb, line 46 def set_url(config_page_or_url) if Nav.is_url? config_page_or_url # Return the given URL if it alreadt is a valid URL return config_page_or_url else # Look for the URL in the config files path_or_url = get_url config_page_or_url if Nav.is_url? path_or_url # If it is a URL now, then return it return path_or_url else # Else add an expected 'root' to the path. return env('root') + path_or_url end end end
to(config_page_or_url, force_refresh = false)
click to toggle source
Navigates to a given URL or page.url configuration if the current URL is not the same Then confirms that the new URL is loaded.
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb, line 9 def to(config_page_or_url, force_refresh = false) url = self.set_url(config_page_or_url) browser.goto url unless url == browser.url and !force_refresh Nav.wait_for_url url end
wait_for_url(url)
click to toggle source
Waits until the browser URL is the same as the given URL
# File lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb, line 16 def wait_for_url(url) browser.wait_until(timeout: 5, message: "URL did not become `#{url}`") { browser.url.include? url } end