Module: Nav

Extended by:
LapisLazuli
Defined in:
lib/lapis_lazuli/generators/cucumber/template/features/helpers/navigation_helper.rb

Overview

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

Constant Summary

Constants included from LapisLazuli

LapisLazuli::CONFIG_OPTIONS, LapisLazuli::PLACEHOLDERS, LapisLazuli::VERSION

Constants included from LapisLazuli::ArgParse

LapisLazuli::ArgParse::ERROR_OPTIONS

Constants included from LapisLazuli::WorldModule::Hooks

LapisLazuli::WorldModule::Hooks::HOOK_QUEUES

Instance Attribute Summary

Attributes included from LapisLazuli

#software_versions

Class Method Summary collapse

Methods included from LapisLazuli

After, Before, Start, fetch_versions

Methods included from LapisLazuli::Assertions

#assertions, #assertions=

Methods included from LapisLazuli::GenericModule::XPath

#xp_and, #xp_contains, #xp_not, #xp_or

Methods included from LapisLazuli::WorldModule::API

#api, #has_api?

Methods included from LapisLazuli::WorldModule::Browser

#browser, #has_browser?

Methods included from LapisLazuli::WorldModule::Browser::ClassMethods

#browser_module, #browser_modules

Methods included from LapisLazuli::WorldModule::Proxy

#has_proxy?, #proxy

Methods included from LapisLazuli::WorldModule::Logging

#log

Methods included from LapisLazuli::WorldModule::Config

#add_config_from_file, #config, #current_env, #env, #env_or_config, #get_config_from_file, #has_config?, #has_env?, #has_env_or_config?, #init, #load_config, #metadata, #var_from_env

Methods included from LapisLazuli::WorldModule::Config::ClassMethods

#add_config, #config_file, #config_file=, #config_files

Methods included from LapisLazuli::WorldModule::Error

#error, #start_debugger

Methods included from LapisLazuli::WorldModule::Annotate

#annotate, #annotations

Methods included from LapisLazuli::ArgParse

#make_list_from_item, #make_list_from_nested, #parse_args

Methods included from LapisLazuli::WorldModule::Variable

#has_storage?, #scenario, #storage, #time, #uuid, #variable, #variable!

Methods included from LapisLazuli::WorldModule::Hooks

add_hook, #after_scenario_hook, #before_scenario_hook

Class Method Details

.get_url(page) ⇒ Object

Loads the URL from the config, prioritized from top to bottom: production.pages.home production.pages.home.path pages.home pages.home.path



27
28
29
30
31
32
33
# 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) ⇒ Boolean

Confirms if the given URL is a valid URL

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# 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) ⇒ Object

returns the expected URL



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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) ⇒ Object

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.



9
10
11
12
13
# 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) ⇒ Object

Waits until the browser URL is the same as the given URL



16
17
18
19
20
# 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