Module: PageNavigation

Defined in:
lib/page_navigation.rb,
lib/page_navigation/routes.rb,
lib/page_navigation/version.rb

Overview

Implements basic navigation capabilities for a collection of classes that implement a PageObject like pattern.

In order to use these two methods you must define routes. A route is simply an array of Class/Method calls and can contain parameters that can be passed to the methods. Here is an example:

Notice the first entry of :another_route is passing an argument to the method.

The user must also maintain an instance variable named @current_page which points to the current object in the array.

Examples:

Example routes defined in env.rb

MyNavigator.routes = {
  :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
  :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
}

Defined Under Namespace

Modules: Routes

Constant Summary collapse

VERSION =
'0.10'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clsObject



32
33
34
# File 'lib/page_navigation.rb', line 32

def self.cls
  @cls
end

.included(cls) ⇒ Object



27
28
29
30
# File 'lib/page_navigation.rb', line 27

def self.included(cls)
  cls.extend PageNavigation::Routes
  @cls = cls
end

Instance Method Details

#continue_navigation_to(page_cls, how = {:using => :default}, &block) ⇒ PageObject

Same as navigate_to except it will start at the @current_page instead the beginning of the path.

:using. This will be used to lookup the route. It has a default value of :default.

Parameters:

  • page_cls (PageObject)

    a class that implements the PageObject pattern.

  • how (Hash) (defaults to: {:using => :default})

    a hash that contains an element with the key

  • block (block)

    an optional block to be called

Returns:

  • (PageObject)

    the page you are navigating to



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/page_navigation.rb', line 83

def continue_navigation_to(page_cls, how = {:using => :default}, &block)
  path = path_for how
  from_index = find_index_for(path, @current_page.class)
  to_index = find_index_for(path, page_cls)-1
  if from_index == to_index
    navigate_through_pages([path[from_index]], false)
  else
    navigate_through_pages(path[from_index..to_index], false)
  end
  on(page_cls, &block)
end

Navigate through a complete route.

This method will navigate an entire route executing all of the methods. Since it completes the route it does not return any pages and it does not accept a block.

:using. This will be used to lookup the route. It has a default value of :default. The other is with the key :visit. This specifies whether to explicitly visit the first page. It has a default value of false.

Examples:

page.navigate_all  # will use the default path
page.navigate_all(:using => :another_route)

Parameters:

  • how (Hash) (defaults to: {:using => :default, :visit => false})

    a hash that contains two elements. One with the key



111
112
113
114
# File 'lib/page_navigation.rb', line 111

def navigate_all(how = {:using => :default, :visit => false})
  path = path_for how
  navigate_through_pages(path[0..-1], how[:visit])
end

Navigate to a specific page following a predefined path.

This method requires a lot of setup. See the documentation for this module. Once the setup is complete you can navigate to a page traversing through all other pages along the way. It will call the method you specified in the routes for each page as it navigates. Using the example setup defined in the documentation above you can call the method two ways:

:using. This will be used to lookup the route. It has a default value of :default. The other is with the key :visit. This specifies whether to explicitly visit the first page. It has a default value of false.

Examples:

page.navigate_to(PageThree)  # will use the default path
page.navigate_to(PageThree, :using => :another_route)

Parameters:

  • page_cls (PageObject)

    a class that implements the PageObject pattern.

  • how (Hash) (defaults to: {:using => :default, :visit => false})

    a hash that contains two elements. One with the key

  • block (block)

    an optional block to be called

Returns:

  • (PageObject)

    the page you are navigating to



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/page_navigation.rb', line 58

def navigate_to(page_cls, how = {:using => :default, :visit => false}, &block)
  how[:using] = :default unless how[:using]
  how[:visit] = false unless how[:visit]
  path = path_for how
  to_index = find_index_for(path, page_cls)-1
  if to_index == -1
    return on(page_cls, &block)
  else
    start = how[:from] ? path.find_index { |entry| entry[0] == how[:from] } : 0
    navigate_through_pages(path[start..to_index], how[:visit])
  end
  on(page_cls, &block)
end