Module: WatirRobot::Page
- Included in:
- KeywordLibrary
- Defined in:
- lib/watir_robot/keywords/page.rb
Overview
Functionality scoped against the entire HTML page
Instance Method Summary collapse
-
#execute_javascript(code) ⇒ Object
Execute arbitrary JavaScript.
-
#get_all_elements_by_xpath(xpath, sep = ';;') ⇒ String
Get the text of all elements that match a given XPath query.
-
#get_page_source ⇒ String
Get source of page.
-
#get_page_status ⇒ String
Get status of page (located at bottom of browser window).
-
#get_page_text ⇒ String
Get text of a page.
-
#get_title ⇒ String
Get page title.
-
#log_page_source ⇒ Object
Log page source in a readable format.
-
#page_should_contain(text) ⇒ Object
Verify page text contains a certain value.
-
#page_should_contain_area(loc) ⇒ Object
Verify area tag exists on page.
-
#page_should_contain_button(loc) ⇒ Object
Verify button exists on page.
-
#page_should_contain_checkbox(loc) ⇒ Object
Verify checkbox exists on page.
-
#page_should_contain_element(loc) ⇒ Object
Verify element exists on page.
-
#page_should_contain_form(loc) ⇒ Object
Verify form exists on page.
-
#page_should_contain_image(loc) ⇒ Object
Verify image exists on page.
-
#page_should_contain_link(loc) ⇒ Object
Verify link exists on page.
-
#page_should_contain_list(loc, ordered = nil) ⇒ Object
Verify list exists on page.
-
#page_should_contain_radio_button(loc) ⇒ Object
Verify radio button exists on page.
-
#page_should_contain_select_list(loc) ⇒ Object
Verify select list does exist on page.
-
#page_should_contain_textfield(loc) ⇒ Object
Verify link exists on page.
-
#page_should_not_contain(text) ⇒ Object
Verify page text does not contain a certain value.
-
#page_should_not_contain_area(loc) ⇒ Object
Verify area tag exists on page.
-
#page_should_not_contain_button(loc) ⇒ Object
Verify button does not exist on page.
-
#page_should_not_contain_checkbox(loc) ⇒ Object
Verify checkbox does not exist on page.
-
#page_should_not_contain_element(loc) ⇒ Object
Verify element does not exist on page.
-
#page_should_not_contain_form(loc) ⇒ Object
Verify form does not exist on page.
-
#page_should_not_contain_image(loc) ⇒ Object
Verify image does not exist on page.
-
#page_should_not_contain_link(loc) ⇒ Object
Verify link does not exist on page.
-
#page_should_not_contain_list(loc, ordered = nil) ⇒ Object
Verify list does not exist on page.
-
#page_should_not_contain_radio_button(loc) ⇒ Object
Verify radio button does not exist on page.
-
#page_should_not_contain_select_list(loc) ⇒ Object
Verify select list does not exist on page.
-
#page_should_not_contain_textfield(loc) ⇒ Object
Verify link does not exist on page.
-
#title_should_be(title) ⇒ Object
Verify page title, i.e.
-
#title_should_contain(text) ⇒ Object
Verify that the page title contains a certain value.
Instance Method Details
#execute_javascript(code) ⇒ Object
Execute arbitrary JavaScript
70 71 72 |
# File 'lib/watir_robot/keywords/page.rb', line 70 def execute_javascript(code) @browser.execute_script(code) end |
#get_all_elements_by_xpath(xpath, sep = ';;') ⇒ String
Get the text of all elements that match a given XPath query
59 60 61 62 63 64 65 |
# File 'lib/watir_robot/keywords/page.rb', line 59 def get_all_elements_by_xpath(xpath, sep = ';;') matches = [] @browser.elements_by_xpath(xpath).each do |element| matches << element.text end return matches.join(sep) end |
#get_page_source ⇒ String
Get source of page
22 23 24 |
# File 'lib/watir_robot/keywords/page.rb', line 22 def get_page_source @browser.html end |
#get_page_status ⇒ String
Get status of page (located at bottom of browser window)
40 41 42 |
# File 'lib/watir_robot/keywords/page.rb', line 40 def get_page_status @browser.status end |
#get_page_text ⇒ String
Get text of a page
31 32 33 |
# File 'lib/watir_robot/keywords/page.rb', line 31 def get_page_text @browser.text end |
#get_title ⇒ String
Get page title
48 49 50 |
# File 'lib/watir_robot/keywords/page.rb', line 48 def get_title @browser.title end |
#log_page_source ⇒ Object
Log page source in a readable format
13 14 15 |
# File 'lib/watir_robot/keywords/page.rb', line 13 def log_page_source print @browser.html end |
#page_should_contain(text) ⇒ Object
Verify page text contains a certain value
82 83 84 85 |
# File 'lib/watir_robot/keywords/page.rb', line 82 def page_should_contain(text) raise(Exception::PageMatchError, "The expected text #{text} was not contained in the page: #{@browser.text}") unless @browser.text.include? text end |
#page_should_contain_area(loc) ⇒ Object
Verify area tag exists on page
102 103 104 105 |
# File 'lib/watir_robot/keywords/page.rb', line 102 def page_should_contain_area(loc) raise(Exception::ElementDoesNotExist, "The area described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.area(parse_location(loc)).exists? end |
#page_should_contain_button(loc) ⇒ Object
Verify button exists on page
122 123 124 125 |
# File 'lib/watir_robot/keywords/page.rb', line 122 def (loc) raise(Exception::ElementDoesNotExist, "The button described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.(parse_location(loc)).exists? end |
#page_should_contain_checkbox(loc) ⇒ Object
Verify checkbox exists on page
142 143 144 145 |
# File 'lib/watir_robot/keywords/page.rb', line 142 def page_should_contain_checkbox(loc) raise(Exception::ElementDoesNotExist, "The checkbox described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.checkbox(parse_location(loc)).exists? end |
#page_should_contain_element(loc) ⇒ Object
Verify element exists on page
162 163 164 165 |
# File 'lib/watir_robot/keywords/page.rb', line 162 def page_should_contain_element(loc) raise(Exception::ElementDoesNotExist, "The element described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.element(parse_location(loc)).exists? end |
#page_should_contain_form(loc) ⇒ Object
Verify form exists on page
182 183 184 185 |
# File 'lib/watir_robot/keywords/page.rb', line 182 def page_should_contain_form(loc) raise(Exception::ElementDoesNotExist, "The form described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.form(parse_location(loc)).exists? end |
#page_should_contain_image(loc) ⇒ Object
Verify image exists on page
202 203 204 205 |
# File 'lib/watir_robot/keywords/page.rb', line 202 def page_should_contain_image(loc) raise(Exception::ElementDoesNotExist, "The image described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.image(parse_location(loc)).exists? end |
#page_should_contain_link(loc) ⇒ Object
Verify link exists on page
222 223 224 225 |
# File 'lib/watir_robot/keywords/page.rb', line 222 def page_should_contain_link(loc) raise(Exception::ElementDoesNotExist, "The link described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.link(parse_location(loc)).exists? end |
#page_should_contain_list(loc, ordered = nil) ⇒ Object
Verify list exists on page
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/watir_robot/keywords/page.rb', line 243 def page_should_contain_list(loc, ordered = nil) ordered = ordered.downcase unless ordered.nil? if ordered.nil? # Not specified; match either raise(Exception::ElementDoesNotExist, "The list described by #{loc} is not contained within the page:\n#{@browser.html}") unless (@browser.ol(parse_location(loc)).exists? || @browser.ul(parse_location(loc)).exists?) elsif ordered == 'true' raise(Exception::ElementDoesNotExist, "The ordered list described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.ol(parse_location(loc)).exists? elsif ordered == 'false' raise(Exception::ElementDoesNotExist, "The unordered list described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.ul(parse_location(loc)).exists? else raise(ArgumentError, "If you specify ordered vs. unordered lists, the only valid values are 'true' or 'false' (case-insensitive)") end end |
#page_should_contain_radio_button(loc) ⇒ Object
Verify radio button exists on page
288 289 290 291 |
# File 'lib/watir_robot/keywords/page.rb', line 288 def (loc) raise(Exception::ElementDoesNotExist, "The radio button described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.radio(parse_location(loc)).exists? end |
#page_should_contain_select_list(loc) ⇒ Object
Verify select list does exist on page
308 309 310 311 |
# File 'lib/watir_robot/keywords/page.rb', line 308 def page_should_contain_select_list(loc) raise(Exception::ElementDoesNotExist, "The select list described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.select(parse_location(loc)).exists? end |
#page_should_contain_textfield(loc) ⇒ Object
Verify link exists on page
328 329 330 331 |
# File 'lib/watir_robot/keywords/page.rb', line 328 def page_should_contain_textfield(loc) raise(Exception::ElementDoesNotExist, "The text field described by #{loc} is not contained within the page:\n#{@browser.html}") unless @browser.text_field(parse_location(loc)).exists? end |
#page_should_not_contain(text) ⇒ Object
Verify page text does not contain a certain value
92 93 94 95 |
# File 'lib/watir_robot/keywords/page.rb', line 92 def page_should_not_contain(text) raise(Exception::PageMatchError, "The expected text #{text} was contained in the page erroneously: #{@browser.text}") if @browser.text.include? text end |
#page_should_not_contain_area(loc) ⇒ Object
Verify area tag exists on page
112 113 114 115 |
# File 'lib/watir_robot/keywords/page.rb', line 112 def page_should_not_contain_area(loc) raise(Exception::ElementExists, "The area described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.area(parse_location(loc)).exists? end |
#page_should_not_contain_button(loc) ⇒ Object
Verify button does not exist on page
132 133 134 135 |
# File 'lib/watir_robot/keywords/page.rb', line 132 def (loc) raise(Exception::ElementExists, "The button described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.(parse_location(loc)).exists? end |
#page_should_not_contain_checkbox(loc) ⇒ Object
Verify checkbox does not exist on page
152 153 154 155 |
# File 'lib/watir_robot/keywords/page.rb', line 152 def page_should_not_contain_checkbox(loc) raise(Exception::ElementExists, "The checkbox described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.checkbox(parse_location(loc)).exists? end |
#page_should_not_contain_element(loc) ⇒ Object
Verify element does not exist on page
172 173 174 175 |
# File 'lib/watir_robot/keywords/page.rb', line 172 def page_should_not_contain_element(loc) raise(Exception::ElementExists, "The element described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.element(parse_location(loc)).exists? end |
#page_should_not_contain_form(loc) ⇒ Object
Verify form does not exist on page
192 193 194 195 |
# File 'lib/watir_robot/keywords/page.rb', line 192 def page_should_not_contain_form(loc) raise(Exception::ElementExists, "The form described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.form(parse_location(loc)).exists? end |
#page_should_not_contain_image(loc) ⇒ Object
Verify image does not exist on page
212 213 214 215 |
# File 'lib/watir_robot/keywords/page.rb', line 212 def page_should_not_contain_image(loc) raise(Exception::ElementExists, "The image described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.image(parse_location(loc)).exists? end |
#page_should_not_contain_link(loc) ⇒ Object
Verify link does not exist on page
232 233 234 235 |
# File 'lib/watir_robot/keywords/page.rb', line 232 def page_should_not_contain_link(loc) raise(Exception::ElementExists, "The link described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.link(parse_location(loc)).exists? end |
#page_should_not_contain_list(loc, ordered = nil) ⇒ Object
Verify list does not exist on page
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/watir_robot/keywords/page.rb', line 266 def page_should_not_contain_list(loc, ordered = nil) ordered = ordered.downcase unless ordered == nil if ordered.nil? # Not specified; match either raise(Exception::ElementExists, "The list described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if (@browser.ol(parse_location(loc)).exists? || @browser.ul(parse_location(loc)).exists?) elsif ordered == 'true' raise(Exception::ElementExists, "The ordered list described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.ol(parse_location(loc)).exists? elsif ordered == 'false' raise(Exception::ElementExists, "The unordered list described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.ul(parse_location(loc)).exists? else raise(ArgumentError, "If you specify ordered vs. unordered lists, the only valid values are 'true' or 'false' (case-insensitive)") end end |
#page_should_not_contain_radio_button(loc) ⇒ Object
Verify radio button does not exist on page
298 299 300 301 |
# File 'lib/watir_robot/keywords/page.rb', line 298 def (loc) raise(Exception::ElementExists, "The radio button described by #{loc} is erroneously contained within the page:\n#{@browser.html}") if @browser.radio(parse_location(loc)).exists? end |
#page_should_not_contain_select_list(loc) ⇒ Object
Verify select list does not exist on page
318 319 320 321 |
# File 'lib/watir_robot/keywords/page.rb', line 318 def page_should_not_contain_select_list(loc) raise(Exception::ElementExists, "The select list described by #{loc} is not contained within the page erroneously:\n#{@browser.html}") if @browser.select(parse_location(loc)).exists? end |
#page_should_not_contain_textfield(loc) ⇒ Object
Verify link does not exist on page
338 339 340 341 |
# File 'lib/watir_robot/keywords/page.rb', line 338 def page_should_not_contain_textfield(loc) raise(Exception::ElementExists, "The text field described by #{loc} is not contained within the page erroneously:\n#{@browser.html}") if @browser.text_field(parse_location(loc)).exists? end |
#title_should_be(title) ⇒ Object
Verify page title, i.e. the <title> in <head>
348 349 350 |
# File 'lib/watir_robot/keywords/page.rb', line 348 def title_should_be(title) raise(Exception::TitleMatchError, "The page title #{@browser.title} is not correct; it should be #{title}") unless @browser.title == title end |
#title_should_contain(text) ⇒ Object
Verify that the page title contains a certain value
357 358 359 |
# File 'lib/watir_robot/keywords/page.rb', line 357 def title_should_contain(text) raise(Exception::TitleMatchError, "The page title #{@browser.url} is not correct; it should contain #{text}") unless @browser.title.include?(text) end |