Module: Symbiont::Pages

Includes:
Helpers
Defined in:
lib/symbiont/pages.rb

Instance Method Summary collapse

Instance Method Details

#asserted_titleObject



42
43
44
# File 'lib/symbiont/pages.rb', line 42

def asserted_title
  self.class.asserted_title
end

#asserted_urlObject



34
35
36
# File 'lib/symbiont/pages.rb', line 34

def asserted_url
  self.class.asserted_url
end

#clear_cookiesObject Also known as: remove_cookies



81
82
83
# File 'lib/symbiont/pages.rb', line 81

def clear_cookies
  browser.cookies.clear
end

#displayed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/symbiont/pages.rb', line 26

def displayed?
  has_correct_url?
end


74
75
76
77
78
79
# File 'lib/symbiont/pages.rb', line 74

def get_cookie(name)
  browser.cookies.to_a.each do |cookie|
    return cookie[:value] if cookie[:name] == name
  end
  nil
end

#has_correct_title?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/symbiont/pages.rb', line 16

def has_correct_title?
  no_title_is_provided if asserted_title.nil?
  !(browser.title.match(asserted_title)).nil?
end

#has_correct_url?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/symbiont/pages.rb', line 11

def has_correct_url?
  no_url_matches_is_provided if url_match.nil?
  !(browser.url =~ url_match).nil?
end

#markupObject Also known as: html



50
51
52
# File 'lib/symbiont/pages.rb', line 50

def markup
  browser.html
end

#refreshObject Also known as: refresh_page



85
86
87
# File 'lib/symbiont/pages.rb', line 85

def refresh
  browser.refresh
end

#run_script(script, *args) ⇒ Object Also known as: execute_script



70
71
72
# File 'lib/symbiont/pages.rb', line 70

def run_script(script, *args)
  browser.execute_script(script, *args)
end

#screenshot(file) ⇒ Object Also known as: save_screenshot



66
67
68
# File 'lib/symbiont/pages.rb', line 66

def screenshot(file)
  browser.wd.save_screenshot(file)
end

#secure?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/symbiont/pages.rb', line 30

def secure?
  !url.match(/^https/).nil?
end

#textObject Also known as: page_text



54
55
56
# File 'lib/symbiont/pages.rb', line 54

def text
  browser.text
end

#titleObject Also known as: page_title



58
59
60
# File 'lib/symbiont/pages.rb', line 58

def title
  browser.title
end

#urlObject Also known as: current_url, page_url



46
47
48
# File 'lib/symbiont/pages.rb', line 46

def url
  browser.url
end

#url_matchObject



38
39
40
# File 'lib/symbiont/pages.rb', line 38

def url_match
  self.class.url_match
end

#verified?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/symbiont/pages.rb', line 21

def verified?
  has_correct_url?
  has_correct_title?
end

#viewObject



5
6
7
8
9
# File 'lib/symbiont/pages.rb', line 5

def view
  no_url_is_provided if asserted_url.nil?
  browser.goto(asserted_url)
  self
end

#visit(url) ⇒ Object Also known as: navigate_to, goto



62
63
64
# File 'lib/symbiont/pages.rb', line 62

def visit(url)
  browser.goto(url)
end

#will_alertString

Returns the message contained in the alert message box.

Returns:

  • (String)

    the message contained in the alert message box



90
91
92
93
94
95
96
97
98
# File 'lib/symbiont/pages.rb', line 90

def will_alert
  yield
  value = nil
  if browser.alert.exists?
    value = browser.alert.text
    browser.alert.ok
  end
  value
end

#will_confirm(response) ⇒ String

Returns the message contained in the confirmation message box.

Parameters:

  • response (Boolean)

    true to accept confirmation, false to cancel it

Returns:

  • (String)

    the message contained in the confirmation message box



102
103
104
105
106
107
108
109
110
# File 'lib/symbiont/pages.rb', line 102

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) ⇒ Hash

the value that the prompt had before the response was applied

Parameters:

  • response (String)

    the value to be used in the prompt

Returns:

  • (Hash)

    :message for the prompt message, :default_value for



115
116
117
118
119
120
121
122
123
124
# File 'lib/symbiont/pages.rb', line 115

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_modalObject

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.



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/symbiont/pages.rb', line 143

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) ⇒ Object Also known as: select_window, attach_to

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.

action on or within the window

Parameters:

  • locator (Hash)

    the :title or :url of the window

  • block (Proc)

    any code that should be executed as an



134
135
136
137
# File 'lib/symbiont/pages.rb', line 134

def within_window(locator, &block)
  identifier = { locator.keys.first => /#{Regexp.escape(locator.values.first)}/ }
  browser.window(identifier).use(&block)
end