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 Method Summary collapse
-
#initialize(interface_type: :none, page_object_dir: 'spec/pages') ⇒ Browser
constructor
A new instance of Browser.
- #load_interface(type: :none) ⇒ Object
- #load_pages ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#require_pages(page_object_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(interface_type: :none, page_object_dir: 'spec/pages') ⇒ Browser
Returns a new instance of Browser.
12 13 14 15 |
# File 'lib/rutl/browser.rb', line 12 def initialize(interface_type: :none, page_object_dir: 'spec/pages') @pages = load_pages(page_object_dir: page_object_dir) load_interface(type: interface_type) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rutl/browser.rb', line 48 def method_missing(method, *args, &block) result = if args.empty? @interface.send(method) else @interface.send(method, *args, &block) end if result.class == Array && (result[0].class.ancestors.include?(BasePage) || result[0].class == Exception) wait_for_transition(result) else result end end |
Instance Method Details
#load_interface(type: :none) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rutl/browser.rb', line 17 def load_interface(type: :none) pages = @pages require "rutl/interface/#{type}_interface" klass = "#{type.to_s.capitalize}Interface" @interface = Object.const_get(klass).new(pages: pages) @interface.interface = @interface end |
#load_pages ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rutl/browser.rb', line 37 def load_pages(*) pages = [] names = require_pages names.each do |klass| # Don't have @interface set yet. # That would have been the param to new, :interface. pages << Object.const_get(klass).new end pages end |
#require_pages(page_object_dir: 'spec/pages') ⇒ Object
Ugly. Requires files for page objects. Returns array of class names to load.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rutl/browser.rb', line 26 def require_pages(page_object_dir: 'spec/pages') names = [] Dir["#{page_object_dir}/*"].each do |file| require "rutl/../../#{file}" File.open(file).each do |line| names << $1 if line =~ /class (.*) < BasePage/ 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 |