Class: Simplexframe::Navigator

Inherits:
Object
  • Object
show all
Defined in:
lib/simplexframe/simple_navigator.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Navigator

Returns a new instance of Navigator.



5
6
7
8
9
10
11
12
# File 'lib/simplexframe/simple_navigator.rb', line 5

def initialize config
  @config = config.clone
  defined_browser?
  @browser = start_browser
  @browser.cookies.clear
  raise "can not start browser, maybe you need to download the driver for #{@config.browser}" if @browser.nil?
  define_goto_methods
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &blk) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/simplexframe/simple_navigator.rb', line 46

def method_missing(m, *args, &blk)
  if @browser.respond_to? m
    @browser.send(m, *args, &blk)
  else
    super
  end #if

end

Instance Method Details

#define_goto_methodsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simplexframe/simple_navigator.rb', line 24

def define_goto_methods
  p Module.constants.grep(/Page$/) if $debug
  Module.constants.grep(/Page$/).each do |page_klass|
    if simplexframe_page?(page_klass)
      # define_method is private,so using send

      self.class.send :define_method, "goto_#{page_klass.to_s.underscore}" do
        page = Module.const_get(page_klass).new(@browser)
        page.goto
        page
      end #define_method

      puts "defined goto_#{page_klass.to_s.underscore}" if $debug
    end #if

  end #each

end

#defined_browser?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/simplexframe/simple_navigator.rb', line 14

def defined_browser?
  if !@config.respond_to?(:browser) || @config.browser.empty?
    raise IncorrectConfigFileError, 'you should define browser in your config file'
  end #if

end

#start_browserObject



20
21
22
# File 'lib/simplexframe/simple_navigator.rb', line 20

def start_browser
  Watir::Browser.new @config.browser.to_sym
end

#valid_page_klass?(klass) ⇒ Boolean Also known as: simplexframe_page?

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/simplexframe/simple_navigator.rb', line 39

def valid_page_klass? klass
  # skip Simplexframe::Page

  return false if klass.eql?(:Page)
  Module.const_get(klass) < Simplexframe::Page
end