module Symbiont::Pages

Public Instance Methods

asserted_title() click to toggle source
# File lib/symbiont/pages.rb, line 49
def asserted_title
  self.class.asserted_title
end
asserted_url() click to toggle source
# File lib/symbiont/pages.rb, line 41
def asserted_url
  self.class.asserted_url
end
attach_to(locator, &block)
Alias for: within_window
clear_cookies() click to toggle source
# File lib/symbiont/pages.rb, line 88
def clear_cookies
  browser.cookies.clear
end
Also aliased as: remove_cookies
current_url()
Alias for: url
displayed?() click to toggle source
# File lib/symbiont/pages.rb, line 33
def displayed?
  has_correct_url?
end
execute_script(script, *args)
Alias for: run_script
goto(url)
Alias for: visit
has_correct_title?() click to toggle source
# File lib/symbiont/pages.rb, line 23
def has_correct_title?
  no_title_is_provided if asserted_title.nil?
  !(browser.title.match(asserted_title)).nil?
end
has_correct_url?() click to toggle source
# File lib/symbiont/pages.rb, line 18
def has_correct_url?
  no_url_matches_is_provided if url_match.nil?
  !(browser.url =~ url_match).nil?
end
html()
Alias for: markup
markup() click to toggle source
# File lib/symbiont/pages.rb, line 57
def markup
  browser.html
end
Also aliased as: html
navigate_to(url)
Alias for: visit
page_text()
Alias for: text
page_title()
Alias for: title
page_url()
Alias for: url
perform() click to toggle source
# File lib/symbiont/pages.rb, line 14
def perform
  view
end
refresh() click to toggle source
# File lib/symbiont/pages.rb, line 92
def refresh
  browser.refresh
end
Also aliased as: refresh_page
refresh_page()
Alias for: refresh
remove_cookies()
Alias for: clear_cookies
run_script(script, *args) click to toggle source
# File lib/symbiont/pages.rb, line 77
def run_script(script, *args)
  browser.execute_script(script, *args)
end
Also aliased as: execute_script
save_screenshot(file)
Alias for: screenshot
screenshot(file) click to toggle source
# File lib/symbiont/pages.rb, line 73
def screenshot(file)
  browser.wd.save_screenshot(file)
end
Also aliased as: save_screenshot
secure?() click to toggle source
# File lib/symbiont/pages.rb, line 37
def secure?
  !url.match(/^https/).nil?
end
select_window(locator, &block)
Alias for: within_window
text() click to toggle source
# File lib/symbiont/pages.rb, line 61
def text
  browser.text
end
Also aliased as: page_text
title() click to toggle source
# File lib/symbiont/pages.rb, line 65
def title
  browser.title
end
Also aliased as: page_title
url() click to toggle source
# File lib/symbiont/pages.rb, line 53
def url
  browser.url
end
Also aliased as: current_url, page_url
url_match() click to toggle source
# File lib/symbiont/pages.rb, line 45
def url_match
  self.class.url_match
end
verified?() click to toggle source
# File lib/symbiont/pages.rb, line 28
def verified?
  has_correct_url?
  has_correct_title?
end
view(&block) click to toggle source
# File lib/symbiont/pages.rb, line 7
def view(&block)
  no_url_is_provided if asserted_url.nil?
  browser.goto(asserted_url)
  when_ready(&block) if block_given?
  self
end
visit(url) click to toggle source
# File lib/symbiont/pages.rb, line 69
def visit(url)
  browser.goto(url)
end
Also aliased as: navigate_to, goto
will_alert() { || ... } click to toggle source

@return [String] the message contained in the alert message box

# File lib/symbiont/pages.rb, line 97
def will_alert
  yield
  value = nil
  if browser.alert.exists?
    value = browser.alert.text
    browser.alert.ok
  end
  value
end
will_confirm(response) { || ... } click to toggle source

@param response [Boolean] true to accept confirmation, false to cancel it @return [String] the message contained in the confirmation message box

# File lib/symbiont/pages.rb, line 109
def will_confirm(response)
  yield
  value = nil
  if browser.alert.exists?
    value = browser.alert.text
    response ? browser.alert.ok : browser.alert.close
  end
  value
end
will_prompt(response) { || ... } click to toggle source

@param response [String] the value to be used in the prompt @return [Hash] :message for the prompt message, :default_value for the value that the prompt had before the response was applied

# File lib/symbiont/pages.rb, line 122
def will_prompt(response)
  cmd = "window.prompt = function(text, value) \
    {window.__lastWatirPrompt = {message: text, default_value: value}; \
    return '#{response}';}"
  browser.wd.execute_script(cmd)
  yield
  result = browser.wd.execute_script('return window.__lastWatirPrompt')
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
  result
end
within_modal() { || ... } click to toggle source

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.

# File lib/symbiont/pages.rb, line 150
def within_modal
  convert_modal_to_window = %{
    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
within_window(locator, &block) click to toggle source

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

# File lib/symbiont/pages.rb, line 141
def within_window(locator, &block)
  identifier = { locator.keys.first => /#{Regexp.escape(locator.values.first)}/ }
  browser.window(identifier).use(&block)
end
Also aliased as: select_window, attach_to