lib/taza/site.rb in bret-watircraft-0.4.3 vs lib/taza/site.rb in bret-watircraft-0.4.4
- old
+ new
@@ -79,37 +79,49 @@
@module_name = self.class.parent.to_s
@class_name = self.class.to_s.split("::").last
define_flows
- if params[:browser]
- @browser = params[:browser]
- else
- @browser = Browser.create(config)
- @i_created_browser = true
- end
-
page_loader = PageLoader.new(@module_name, pages_path)
@pages = page_loader.page_names
@methods_module = page_loader.page_methods
@methods_module.send(:include, Methods)
self.extend(@methods_module)
-
- @browser.goto origin
+ @browser = params[:browser]
+ initialize_browser
+
execute_block_and_close_browser(&block) if block_given?
end
+
+ # Initializes browser based on configuration settings.
+ 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
def config
Settings.config(@class_name)
end
# The base url of the site. This is configured in environments.yml.
def origin
config[:url]
end
+ def bring_to_front_if_appropriate
+ return unless config[:bring_to_front]
+ return unless config[:browser] == 'ie'
+ @browser.bring_to_front
+ end
+
def execute_block_and_close_browser
begin
yield self
rescue => site_block_exception
ensure
@@ -129,10 +141,10 @@
@@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 if @i_created_browser
+ @browser.close unless @leave_open
ensure
raise before_browser_closes_block_exception if before_browser_closes_block_exception
end
end