Class: Browser
Overview
Currently called Browser, this top-level class controls a browser and a fake browser. It will soon call into apps, at which point I need to rethink this naming convention.
Constant Summary
Constants included from Utilities
Utilities::DEFAULT_TIMEOUT, Utilities::POLL_SLEEP_TIME
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
Instance Method Summary collapse
-
#initialize(type:, rutl_pages: RUTL::PAGES || ENV['RUTL_PAGES']) ⇒ Browser
constructor
A new instance of Browser.
- #load_interface(type) ⇒ Object
- #load_pages ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#require_pages(dir: 'spec/pages') ⇒ Object
Ugly.
- #respond_to_missing?(*args) ⇒ Boolean
Methods included from Utilities
#await, #class_info, #location, #page?, #raise_if_not_page
Constructor Details
#initialize(type:, rutl_pages: RUTL::PAGES || ENV['RUTL_PAGES']) ⇒ Browser
Returns a new instance of Browser.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rutl/browser.rb', line 14 def initialize(type:, rutl_pages: RUTL::PAGES || ENV['RUTL_PAGES']) if rutl_pages.nil? || rutl_pages.empty? raise "Set RUTL::PAGES or ENV['RUTL_PAGES'] or pass dir as rutl_pages:" end # This is kind of evil. Figure out how to ditch the $ variable. $browser = self @interface = nil @interface = load_interface(type) @interface.pages = load_pages(dir: rutl_pages) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/rutl/browser.rb', line 54 def method_missing(method, *args, &block) if args.empty? @interface.send(method) else @interface.send(method, *args, &block) end end |
Instance Attribute Details
#interface ⇒ Object (readonly)
Returns the value of attribute interface.
12 13 14 |
# File 'lib/rutl/browser.rb', line 12 def interface @interface end |
Instance Method Details
#load_interface(type) ⇒ Object
25 26 27 28 29 |
# File 'lib/rutl/browser.rb', line 25 def load_interface(type) require "rutl/interface/#{type}_interface" klass = "#{type.to_s.capitalize}Interface" Object.const_get(klass).new end |
#load_pages ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/rutl/browser.rb', line 44 def load_pages(*) pages = [] require_pages.each do |klass| # Don't have @interface set yet. # That would have been the param to new, :interface. pages << Object.const_get(klass).new(@interface) end pages end |
#require_pages(dir: 'spec/pages') ⇒ Object
Ugly. Requires files for page objects. Returns array of class names to load.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rutl/browser.rb', line 32 def require_pages(dir: 'spec/pages') names = [] Dir["#{dir}/*"].each do |file| require "rutl/../../#{file}" File.open(file).each do |line| bingo = line.match(/class (.*) < BasePage/) names << bingo[1] if bingo && bingo[1] end end names end |
#respond_to_missing?(*args) ⇒ Boolean
62 63 64 |
# File 'lib/rutl/browser.rb', line 62 def respond_to_missing?(*args) @interface.respond_to?(*args) end |