Class: Taza::Site
Overview
An abstraction of a website, but more really a container for a sites pages.
You can generate a site by performing the following command:
$ ./script/generate site google
This will generate a site file for google, a flows folder, and a pages folder in lib
Example:
require 'taza'
class Google < Taza::Site
end
Defined Under Namespace
Modules: Methods Classes: PageLoader
Constant Summary collapse
- @@before_browser_closes =
Proc.new() {}
Instance Attribute Summary collapse
-
#methods_module ⇒ Object
Site.
Class Method Summary collapse
-
.before_browser_closes(&block) ⇒ Object
Use this to do something with the browser before it closes, but note that it is a class method which means that this will get called for any instance of a site.
Instance Method Summary collapse
- #bring_to_front_if_appropriate ⇒ Object
- #close ⇒ Object
- #config ⇒ Object
-
#execution_context ⇒ Object
Return a context that supports the “watircraft” commands.
-
#initialize(params = {}, &block) ⇒ Site
constructor
A site can be called a few different ways.
-
#initialize_browser ⇒ Object
Initializes browser based on configuration settings.
- #initialize_context!(context) ⇒ Object
-
#origin ⇒ Object
The base url of the site.
Constructor Details
#initialize(params = {}, &block) ⇒ Site
A site can be called a few different ways
The following example creates a new browser object and closes it:
Google.new do
google.search.set "taza"
google.submit.click
end
This example will create a browser object but not close it:
Google.new.search.set "taza"
Sites can take a couple of parameters in the constructor:
:browser => a browser object to act on instead of creating one automatically
(not sure if this is a useful feature or not)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/taza/site.rb', line 78 def initialize(params={}, &block) @site = self @parent_module = self.class.parent @module_name = @parent_module.to_s @class_name = self.class.to_s.split("::").last define_flows load_methods_files page_loader = PageLoader.new(@module_name, pages_path) @pages = page_loader.page_names @methods_module = page_loader.page_methods @methods_module.send(:include, Methods) @methods_module.send(:include, Spec::Matchers) @methods_module.send(:include, @parent_module::Methods) if defined?(@parent_module::Methods) self.extend(@methods_module) @browser = params[:browser] initialize_browser execute_block_and_close_browser(&block) if block_given? end |
Instance Attribute Details
#methods_module ⇒ Object
Site
62 63 64 |
# File 'lib/taza/site.rb', line 62 def methods_module @methods_module end |
Class Method Details
.before_browser_closes(&block) ⇒ Object
Use this to do something with the browser before it closes, but note that it is a class method which means that this will get called for any instance of a site.
Here’s an example of how you might use it to print the DOM output of a browser before it closes:
Taza::Site.before_browser_closes do |browser|
puts browser.html
end
57 58 59 |
# File 'lib/taza/site.rb', line 57 def self.before_browser_closes(&block) @@before_browser_closes = block end |
Instance Method Details
#bring_to_front_if_appropriate ⇒ Object
122 123 124 125 126 |
# File 'lib/taza/site.rb', line 122 def bring_to_front_if_appropriate return unless config[:bring_to_front] return unless config[:browser] == 'ie' @browser.bring_to_front end |
#close ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/taza/site.rb', line 144 def close begin @@before_browser_closes.call(@browser) rescue => before_browser_closes_block_exception "" # so basically rcov has a bug where it would insist this block is uncovered when empty end begin @browser.close unless @leave_open ensure raise before_browser_closes_block_exception if before_browser_closes_block_exception end end |
#config ⇒ Object
113 114 115 |
# File 'lib/taza/site.rb', line 113 def config Settings.config(@class_name) end |
#execution_context ⇒ Object
Return a context that supports the “watircraft” commands. Currently used by the scriptconsole
159 160 161 |
# File 'lib/taza/site.rb', line 159 def execution_context initialize_context!(Object.new) end |
#initialize_browser ⇒ Object
Initializes browser based on configuration settings.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/taza/site.rb', line 102 def initialize_browser if @browser @leave_open = true else @browser = Browser.create(config) end @browser.goto origin bring_to_front_if_appropriate @leave_open ||= config[:leave_open] end |
#initialize_context!(context) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/taza/site.rb', line 163 def initialize_context!(context) context.extend @methods_module context.site = @site context.browser = @site.browser context end |
#origin ⇒ Object
The base url of the site. This is configured in environments.yml.
118 119 120 |
# File 'lib/taza/site.rb', line 118 def origin config[:url] end |