lib/symbiont/pages.rb in symbiont-0.7.0 vs lib/symbiont/pages.rb in symbiont-0.8.0

- old
+ new

@@ -116,10 +116,39 @@ result = browser.wd.execute_script('return window.__lastWatirPrompt') result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) } result end + # Used to identify a web element or action on a web element as existing + # within an enclosing window object. The window can be referenced using + # either the title attribute of the window or a direct URL. The URL does + # not have to be the entire URL; it can just be a page name. + # + # @param locator [Hash] the :title or :url of the window + # @param block [Proc] any code that should be executed as an + # action on or within the window + def within_window(locator, &block) + identifier = {locator.keys.first => /#{Regexp.escape(locator.values.first)}/} + browser.window(identifier).use(&block) + end + + # Used to identify a web element as existing within an enclosing object + # like a modal dialog box. What this does is override the normal call to + # showModalDialog and opens a window instead. In order to use this new + # window, you have to attach to it. + def within_modal(&block) + convert_modal_to_window = %Q{ + window.showModalDialog = function(sURL, vArguments, sFeatures) { + window.dialogArguments = vArguments; + modalWin = window.open(sURL, 'modal', sFeatures); + return modalWin; + } + } + browser.execute_script(convert_modal_to_window) + yield if block_given? + end + alias_method :current_url, :url alias_method :page_url, :url alias_method :html, :markup alias_method :page_text, :text alias_method :page_title, :title @@ -127,7 +156,9 @@ alias_method :goto, :visit alias_method :save_screenshot, :screenshot alias_method :execute_script, :run_script alias_method :remove_cookies, :clear_cookies alias_method :refresh_page, :refresh + alias_method :select_window, :within_window + alias_method :attach_to, :within_window end end