Class: Lazyman::Navigator
- Inherits:
-
Object
- Object
- Lazyman::Navigator
show all
- Defined in:
- lib/lazyman/lazy_navigator.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config) ⇒ Navigator
Returns a new instance of Navigator.
5
6
7
8
9
10
11
|
# File 'lib/lazyman/lazy_navigator.rb', line 5
def initialize config
@config = config.clone
defined_browser?
@browser = start_browser
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
45
46
47
48
49
50
51
|
# File 'lib/lazyman/lazy_navigator.rb', line 45
def method_missing(m, *args, &blk)
if @browser.respond_to? m
@browser.send(m, *args, &blk)
else
super
end end
|
Instance Method Details
#define_goto_methods ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/lazyman/lazy_navigator.rb', line 23
def define_goto_methods
p Module.constants.grep(/Page$/) if $debug
Module.constants.grep(/Page$/).each do |page_klass|
if lazyman_page?(page_klass)
self.class.send :define_method, "goto_#{page_klass.to_s.underscore}" do
page = Module.const_get(page_klass).new(@browser)
page.goto
page
end puts "defined goto_#{page_klass.to_s.underscore}" if $debug
end end end
|
#defined_browser? ⇒ Boolean
13
14
15
16
17
|
# File 'lib/lazyman/lazy_navigator.rb', line 13
def defined_browser?
if !@config.respond_to?(:browser) || @config.browser.empty?
raise IncorrectConfigFileError, 'you should define browser in your config file'
end end
|
#start_browser ⇒ Object
19
20
21
|
# File 'lib/lazyman/lazy_navigator.rb', line 19
def start_browser
Watir::Browser.new @config.browser.to_sym
end
|
#valid_page_klass?(klass) ⇒ Boolean
Also known as:
lazyman_page?
38
39
40
41
42
|
# File 'lib/lazyman/lazy_navigator.rb', line 38
def valid_page_klass? klass
return false if klass.eql?(:Page)
Module.const_get(klass) < Lazyman::Page
end
|