Module: Symbiont::Pages
- Includes:
- Helpers
- Defined in:
- lib/symbiont/pages.rb
Instance Method Summary collapse
- #asserted_title ⇒ Object
- #asserted_url ⇒ Object
- #clear_cookies ⇒ Object (also: #remove_cookies)
- #displayed? ⇒ Boolean
- #get_cookie(name) ⇒ Object
- #has_correct_title? ⇒ Boolean
- #has_correct_url? ⇒ Boolean
- #markup ⇒ Object (also: #html)
- #perform ⇒ Object
- #refresh ⇒ Object (also: #refresh_page)
- #run_script(script, *args) ⇒ Object (also: #execute_script)
- #screenshot(file) ⇒ Object (also: #save_screenshot)
- #secure? ⇒ Boolean
- #text ⇒ Object (also: #page_text)
- #title ⇒ Object (also: #page_title)
- #url ⇒ Object (also: #current_url, #page_url)
- #url_match ⇒ Object
- #verified? ⇒ Boolean
- #view(&block) ⇒ Object
- #visit(url) ⇒ Object (also: #navigate_to, #goto)
-
#will_alert ⇒ String
The message contained in the alert message box.
-
#will_confirm(response) ⇒ String
The message contained in the confirmation message box.
-
#will_prompt(response) ⇒ Hash
the value that the prompt had before the response was applied.
-
#within_modal ⇒ Object
Used to identify a web element as existing within an enclosing object like a modal dialog box.
-
#within_window(locator, &block) ⇒ Object
(also: #select_window, #attach_to)
Used to identify a web element or action on a web element as existing within an enclosing window object.
Instance Method Details
#asserted_title ⇒ Object
49 50 51 |
# File 'lib/symbiont/pages.rb', line 49 def asserted_title self.class.asserted_title end |
#asserted_url ⇒ Object
41 42 43 |
# File 'lib/symbiont/pages.rb', line 41 def asserted_url self.class.asserted_url end |
#clear_cookies ⇒ Object Also known as:
88 89 90 |
# File 'lib/symbiont/pages.rb', line 88 def browser..clear end |
#displayed? ⇒ Boolean
33 34 35 |
# File 'lib/symbiont/pages.rb', line 33 def displayed? has_correct_url? end |
#get_cookie(name) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/symbiont/pages.rb', line 81 def (name) browser..to_a.each do || return [:value] if [:name] == name end nil end |
#has_correct_title? ⇒ Boolean
23 24 25 26 |
# 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? ⇒ Boolean
18 19 20 21 |
# 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 |
#markup ⇒ Object Also known as: html
57 58 59 |
# File 'lib/symbiont/pages.rb', line 57 def markup browser.html end |
#perform ⇒ Object
14 15 16 |
# File 'lib/symbiont/pages.rb', line 14 def perform view end |
#refresh ⇒ Object Also known as: refresh_page
92 93 94 |
# File 'lib/symbiont/pages.rb', line 92 def refresh browser.refresh end |
#run_script(script, *args) ⇒ Object Also known as: execute_script
77 78 79 |
# File 'lib/symbiont/pages.rb', line 77 def run_script(script, *args) browser.execute_script(script, *args) end |
#screenshot(file) ⇒ Object Also known as: save_screenshot
73 74 75 |
# File 'lib/symbiont/pages.rb', line 73 def screenshot(file) browser.wd.save_screenshot(file) end |
#secure? ⇒ Boolean
37 38 39 |
# File 'lib/symbiont/pages.rb', line 37 def secure? !url.match(/^https/).nil? end |
#text ⇒ Object Also known as: page_text
61 62 63 |
# File 'lib/symbiont/pages.rb', line 61 def text browser.text end |
#title ⇒ Object Also known as: page_title
65 66 67 |
# File 'lib/symbiont/pages.rb', line 65 def title browser.title end |
#url ⇒ Object Also known as: current_url, page_url
53 54 55 |
# File 'lib/symbiont/pages.rb', line 53 def url browser.url end |
#url_match ⇒ Object
45 46 47 |
# File 'lib/symbiont/pages.rb', line 45 def url_match self.class.url_match end |
#verified? ⇒ Boolean
28 29 30 31 |
# File 'lib/symbiont/pages.rb', line 28 def verified? has_correct_url? has_correct_title? end |
#view(&block) ⇒ Object
7 8 9 10 11 12 |
# 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) ⇒ Object Also known as: goto ,
69 70 71 |
# File 'lib/symbiont/pages.rb', line 69 def visit(url) browser.goto(url) end |
#will_alert ⇒ String
Returns the message contained in the alert message box.
97 98 99 100 101 102 103 104 105 |
# 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) ⇒ String
Returns the message contained in the confirmation message box.
109 110 111 112 113 114 115 116 117 |
# 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) ⇒ Hash
the value that the prompt had before the response was applied
122 123 124 125 126 127 128 129 130 131 |
# 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 ⇒ Object
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.
150 151 152 153 154 155 156 157 158 159 160 |
# 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) ⇒ 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
141 142 143 144 |
# 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 |