class Simplexframe::Navigator

Public Class Methods

new(config) click to toggle source
# 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

Public Instance Methods

define_goto_methods() click to toggle source
# File lib/simplexframe/simple_navigator.rb, line 34
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?() click to toggle source
# 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
method_missing(m, *args, &blk) click to toggle source
Calls superclass method
# File lib/simplexframe/simple_navigator.rb, line 56
def method_missing(m, *args, &blk)
        if @browser.respond_to? m
                @browser.send(m, *args, &blk)
        else
                super
        end #if
end
simplexframe_page?(klass)
Alias for: valid_page_klass?
start_browser() click to toggle source
# File lib/simplexframe/simple_navigator.rb, line 20
def start_browser
        
        unless @config.url.nil?
                capabilities = Selenium::WebDriver::Remote::Capabilities.new
                capabilities.browser_name = @config.browser.to_sym

                browser = Watir::Browser.new( 
                        :remote, 
                        :url => @config.url, 
                        :desired_capabilities => capabilities)
        else
                Watir::Browser.new @config.browser.to_sym
        end
end
valid_page_klass?(klass) click to toggle source
# File lib/simplexframe/simple_navigator.rb, line 49
def valid_page_klass? klass
        # skip Simplexframe::Page
        return false if klass.eql?(:Page)
        Module.const_get(klass) < Simplexframe::Page
end
Also aliased as: simplexframe_page?