Module: Awetestlib::Regression::Validations
- Included in:
- Runner
- Defined in:
- lib/awetestlib/regression/validations.rb
Overview
Contains methods to verify content, accessibility, or appearance of page elements.
Core collapse
- #arrays_match?(exp, act, dir, col, org = nil, desc = '') ⇒ Boolean (also: #arrays_match)
-
#checked?(browser, how, what, desc = '') ⇒ Boolean
(also: #checkbox_checked?, #checkbox_set?)
Verify that a checkbox is checked.
-
#date_string_equals?(actual, expected, desc = '', fail_on_format = true) ⇒ Boolean
Verify that date strings represent the same date, allowing for format differences.
-
#disabled?(browser, element, how, what, desc = '') ⇒ Boolean
(also: #validate_not_enabled, #validate_disabled)
Verify that a DOM element is disabled.
-
#does_not_exist?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
(also: #not_exist?)
Verify that a DOM element does not exist on the page.
- #element_contains_text?(browser, element, how, what, expected, desc = '') ⇒ Boolean
-
#enabled?(browser, element, how, what, desc = '') ⇒ Boolean
(also: #validate_enabled)
Verify that a DOM element is enabled.
-
#exists?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element exists on the page.
-
#not_checked?(browser, how, what, desc = '') ⇒ Boolean
Verify that a checkbox is not checked.
-
#not_read_only?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element is not in read-only state.
-
#not_set?(browser, how, what, desc = '', no_fail = false) ⇒ Boolean
(also: #radio_not_set?, #radio_not_checked?, #radio_not_selected?)
Verify that a radio button is not set.
-
#not_visible?(browser, element, how, what, desc = '') ⇒ Boolean
(also: #validate_not_visible)
Verify that a DOM element is not visible.
- #popup_is_browser?(popup, desc = '') ⇒ Boolean (also: #popup_exist, #popup_exists, #popup_exist?, #popup_exists?, #iepopup_exist, #iepopup_exist?, #iepopup_exists, #iepopup_exists?)
-
#radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false) ⇒ Boolean
(also: #radio_set_with_value?)
Verify that a radio button, identified by both the value (what) in attribute how and the value in its value attribute, is set.
-
#read_only?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element is in read-only state.
-
#ready?(browser, element, how, what, value = '', desc = '') ⇒ Boolean
Verify that a DOM element is ready, i.e., both exists and is enabled.
-
#select_list_does_not_include?(browser, how, what, option, desc = '') ⇒ Boolean
Verify that a select list, identified by the value (what) in attribute how, contains an option with the value in option.
-
#select_list_includes?(browser, how, what, option, desc = '') ⇒ Boolean
(also: #validate_select_list_contains, #select_list_contains?)
Verify that a select list, identified by the value (what) in attribute how, contains an option with the value in option.
-
#set?(browser, how, what, desc = '', no_fail = false) ⇒ Boolean
(also: #radio_set?, #radio_checked?, #radio_selected?)
Verify that a radio button is set.
- #string_contains?(strg, target, desc = '') ⇒ Boolean (also: #validate_string, #validate_string_contains)
- #string_does_not_contain?(strg, target, desc = '') ⇒ Boolean (also: #validate_string_not_contains, #validate_string_not_contain, #validate_string_does_not_contain)
-
#string_does_not_equal?(actual, expected, desc = '') ⇒ Boolean
(also: #validate_string_not_equal, #validate_string_does_not_equal)
Compare strings for no match and log results.
-
#string_equals?(actual, expected, desc = '') ⇒ Boolean
(also: #validate_string_equal, #validate_string_equals, #text_equals, #text_equals?)
Compare strings for exact match and log results.
- #text_in_element_equals?(browser, element, how, what, expected, desc = '') ⇒ Boolean
-
#textfield_contains?(browser, how, what, expected, desc = '') ⇒ Boolean
Verify that a text field (also text area), identified by how and what, contains the string specified in expected.
- #textfield_does_not_equal?(browser, how, what, expected, desc = '') ⇒ Boolean (also: #validate_textfield_not_value)
-
#textfield_empty?(browser, how, what, desc = '') ⇒ Boolean
(also: #validate_textfield_empty, #text_field_empty?)
Verify that a text field (also text area), identified by how and what, is empty.
-
#textfield_equals?(browser, how, what, expected, desc = '') ⇒ Boolean
(also: #validate_textfield_value, #text_field_equals?)
Verify that a text field (also text area), identified by how and what, contains only the exact string specified in expected.
-
#validate_list_by_id(browser, what, option, desc = '', select_if_present = true) ⇒ Object
Verify that select list, identified by the value what in the attribute :id, contains text and select it if present.
-
#validate_list_by_name(browser, what, option, desc = '', select_if_present = true) ⇒ Object
Verify that select list contains text.
- #validate_no_text(browser, ptrn, desc = '') ⇒ Object
- #validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5) ⇒ Object
- #validate_select_list_contents(browser, how, what, list) ⇒ Object
- #validate_selected_options(browser, how, what, list, desc = '') ⇒ Object (also: #validate_selections, #validate_select_list_selections)
- #validate_style_greater_than_value(browser, element, how, what, type, value, desc = '') ⇒ Object (also: #validate_style_greaterthan_value)
- #validate_style_less_than_value(browser, element, how, what, type, value, desc = '') ⇒ Object (also: #validate_style_lessthan_value)
-
#validate_style_value(browser, element, how, what, type, expected, desc = '') ⇒ Boolean
Verify that element style attribute contains expected value in style type.
- #validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false) ⇒ Object (also: #validate_link)
-
#validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '') ⇒ Boolean
Verify that a text field (also text area), identified by how and what, contains the string specified in expected.
-
#validate_url(browser, url, desc = '') ⇒ Boolean
Verify that browser is set to a url that is matched by the string or rexexp in url.
-
#visible?(browser, element, how, what, desc = '') ⇒ Boolean
(also: #validate_visible)
Verify that a DOM element is visible.
AutoIT collapse
- #window_does_not_exist?(title) ⇒ Boolean (also: #window_no_exists)
- #window_exists?(title) ⇒ Boolean (also: #window_exists)
Deprecated collapse
- .included(mod) ⇒ Object deprecated Deprecated.
-
#validate_message(browser, message) ⇒ Object
deprecated
Deprecated.
Use #message_to_log
Class Method Details
.included(mod) ⇒ Object
1060 1061 1062 |
# File 'lib/awetestlib/regression/validations.rb', line 1060 def self.included(mod) # puts "RegressionSupport::Validations extended by #{mod}" end |
Instance Method Details
#arrays_match?(exp, act, dir, col, org = nil, desc = '') ⇒ Boolean Also known as: arrays_match
Clarify and rename
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/awetestlib/regression/validations.rb', line 115 def arrays_match?(exp, act, dir, col, org = nil, desc = '') if exp == act passed_to_log("Click on #{dir} column '#{col}' produces expected sorted list. #{desc}") true else failed_to_log("Click on #{dir} column '#{col}' fails to produce expected sorted list. #{desc}") debug_to_log("Original order ['#{org.join("', '")}']") if org debug_to_log("Expected order ['#{exp.join("', '")}']") debug_to_log(" Actual order ['#{act.join("', '")}']") end end |
#checked?(browser, how, what, desc = '') ⇒ Boolean Also known as: checkbox_checked?, checkbox_set?
Verify that a checkbox is checked.
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/awetestlib/regression/validations.rb', line 266 def checked?(browser, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("Checkbox #{how}=>#{what} is checked.", desc) if browser.checkbox(how, what).checked? passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'") end |
#date_string_equals?(actual, expected, desc = '', fail_on_format = true) ⇒ Boolean
Verify that date strings represent the same date, allowing for format differences. Compare strings for no match and log results
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/awetestlib/regression/validations.rb', line 523 def date_string_equals?(actual, expected, desc = '', fail_on_format = true) rtrn = false if actual == expected rtrn = true elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s msg2 "with different formatting. " unless fail_on_format rtrn = true end end msg = ("Actual date '#{actual}' equals expected date '#{expected}'.", msg2, desc) if rtrn passed_to_log("#{msg}") else failed_to_log("#{msg}") end rtrn rescue failed_to_log("Unable to verify that #{msg}. #{$!}") end |
#disabled?(browser, element, how, what, desc = '') ⇒ Boolean Also known as: validate_not_enabled, validate_disabled
Verify that a DOM element is disabled.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/awetestlib/regression/validations.rb', line 166 def disabled?(browser, element, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("#{element.to_s.titlecase} by #{how}=>'#{what}' is disabled.", desc) case element when :textfield, :textarea, :text_area, :text_field rtrn = browser.text_field(how, what).disabled? || browser.text_field(how, what).readonly? when :select_list, :selectlist rtrn = browser.select_list(how, what).disabled? when :checkbox rtrn = browser.checkbox(how, what).disabled? when :radio rtrn = browser.radio(how, what).disabled? when :button rtrn = browser.(how, what).disabled? else rtrn = browser.element(how, what).disabled? end if rtrn passed_to_log("#{msg}") true else failed_to_log("#{msg}") end rtrn rescue failed_to_log("#Unable to verify that #{msg}: '#{$!}'") end |
#does_not_exist?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean Also known as: not_exist?
Verify that a DOM element does not exist on the page.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/awetestlib/regression/validations.rb', line 332 def does_not_exist?(browser, element, how, what, value = nil, desc = '') msg2 = "and value=>'#{value}' " if value msg = ("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'does not exist.', desc) case element when :link bool = browser.link(how, what).exists? else bool = browser.element(how, what).exists? end if bool failed_to_log(msg) else passed_to_log(msg) true end rescue failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}") end |
#element_contains_text?(browser, element, how, what, expected, desc = '') ⇒ Boolean
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
# File 'lib/awetestlib/regression/validations.rb', line 858 def element_contains_text?(browser, element, how, what, expected, desc = '') msg = ("Element #{element} :{how}=>#{what} contains text '#{expected}'.", desc) case how when :href who = browser.element(how, what) else who = browser.link(how, what) end if who text = who.text if expected and expected.length > 0 rgx = Regexp.new(Regexp.escape(expected)) if text =~ rgx passed_to_log(msg) true else debug_to_log("exp: [#{expected.gsub(' ', '^')}]") debug_to_log("act: [#{text.gsub(' ', '^')}]") failed_to_log("#{msg} Found '#{text}'. #{desc}") end else if text.length > 0 debug_to_log("exp: [#{expected.gsub(' ', '^')}]") debug_to_log("act: [#{text.gsub(' ', '^')}]") failed_to_log("#{msg} Found '#{text}'. #{desc}") else passed_to_log(msg) true end end end rescue failed_to_log("Unable to verify #{msg} '#{$!}'") end |
#enabled?(browser, element, how, what, desc = '') ⇒ Boolean Also known as: validate_enabled
Verify that a DOM element is enabled.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/awetestlib/regression/validations.rb', line 139 def enabled?(browser, element, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("#{element.to_s.titlecase} by #{how}=>'#{what}' is enabled.}", desc) case element when :textfield, :textarea, :text_area, :text_field rtrn = browser.text_field(how, what).enabled? and not browser.text_field(how, what).readonly? when :select_list, :selectlist rtrn = browser.select_list(how, what).enabled? else rtrn = browser.element(how, what).enabled? end if rtrn passed_to_log("#{msg}") true else failed_to_log("#{msg}") end rtrn rescue failed_to_log("#Unable to verify that #{msg}': '#{$!}") end |
#exists?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element exists on the page.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/awetestlib/regression/validations.rb', line 310 def exists?(browser, element, how, what, value = nil, desc = '') msg2 = "and value=>'#{value}' " if value msg = ("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists.', desc) case element when :link bool = browser.link(how, what).exists? else bool = browser.element(how, what).exists? end if bool passed_to_log("#{msg}? #{desc}") true else failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]") end rescue failed_to_log("Unable to verify that #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]") end |
#not_checked?(browser, how, what, desc = '') ⇒ Boolean
Verify that a checkbox is not checked.
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/awetestlib/regression/validations.rb', line 285 def not_checked?(browser, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("Checkbox #{how}=>#{what} is not checked.", desc) if not browser.checkbox(how, what).checked? passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'") end |
#not_read_only?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element is not in read-only state.
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/awetestlib/regression/validations.rb', line 567 def not_read_only?(browser, element, how, what, value = nil, desc = '') msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' " msg << "and value=>'#{value}' " if value msg << "is not read only" e = get_element(browser, element, how, what, value) if e if e.readonly? failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]") else passed_to_log("#{msg}? #{desc}") true end end rescue failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]") end |
#not_set?(browser, how, what, desc = '', no_fail = false) ⇒ Boolean Also known as: radio_not_set?, radio_not_checked?, radio_not_selected?
Verify that a radio button is not set.
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/awetestlib/regression/validations.rb', line 380 def not_set?(browser, how, what, desc = '', no_fail = false) #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set? msg = ("Radio #{how}=>#{what} is not selected.", desc) if not browser.radio(how, what).set? passed_to_log(msg) true else if no_fail passed_to_log("Radio #{how}=>#{what} is not selected.") else failed_to_log(msg) end end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'") end |
#not_visible?(browser, element, how, what, desc = '') ⇒ Boolean Also known as: validate_not_visible
Verify that a DOM element is not visible.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/awetestlib/regression/validations.rb', line 231 def not_visible?(browser, element, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("#{element.to_s.titlecase} #{how}=>'#{what}' is not visible.", desc) rtrn = false case how when :index target = get_element(browser, element, how, what) if not target.visible? rtrn = true end else if not browser.element(how, what).visible? rtrn = true end end if rtrn passed_to_log("#{msg}") else failed_to_log("#{msg}") end rtrn rescue failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}") end |
#popup_is_browser?(popup, desc = '') ⇒ Boolean Also known as: popup_exist, popup_exists, popup_exist?, popup_exists?, iepopup_exist, iepopup_exist?, iepopup_exists, iepopup_exists?
759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/awetestlib/regression/validations.rb', line 759 def popup_is_browser?(popup, desc = '') msg = ("Popup: #{popup.title} is a browser window.", desc) if is_browser?(popup) passed_to_log(msg) debug_to_log("\n"+popup.text+"\n") true else failed_to_log(msg) end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'. (#{__LINE__})") end |
#radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false) ⇒ Boolean Also known as: radio_set_with_value?
Verify that a radio button, identified by both the value (what) in attribute how and the value in its value attribute, is set.
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/awetestlib/regression/validations.rb', line 411 def radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false) msg2 = 'not' if no_fail msg = ("Radio #{how}=>#{what} :value=>#{value} is", msg2, 'selected.', desc) if browser.radio(how, what, value).set? passed_to_log(msg) true else if no_fail passed_to_log(msg) else failed_to_log(msg) end end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'") end |
#read_only?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean
Verify that a DOM element is in read-only state.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/awetestlib/regression/validations.rb', line 547 def read_only?(browser, element, how, what, value = nil, desc = '') msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' " msg << "and value=>'#{value}' " if value msg << "read only" e = get_element(browser, element, how, what, value) if e if e.readonly? passed_to_log("#{msg}? #{desc}") true else failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]") end end rescue failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]") end |
#ready?(browser, element, how, what, value = '', desc = '') ⇒ Boolean
Verify that a DOM element is ready, i.e., both exists and is enabled.
587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/awetestlib/regression/validations.rb', line 587 def ready?(browser, element, how, what, value = '', desc = '') msg2 = "and value=>'#{value}' " if value msg = ("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists and is enabled.', desc) e = get_element(browser, element, how, what, value) if e and e.enabled? passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log("Unable to determine if #{msg}. '#{$!}' [#{get_callers(1)}]") end |
#select_list_does_not_include?(browser, how, what, option, desc = '') ⇒ Boolean
Verify that a select list, identified by the value (what) in attribute how, contains an option with the value in option.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/awetestlib/regression/validations.rb', line 463 def select_list_does_not_include?(browser, how, what, option, desc = '') msg = ("Select list #{how}=>#{what} does not include option '#{option}'.", desc) select_list = browser.select_list(how, what) = select_list. if option if not .include?(option) passed_to_log(msg) true else failed_to_log(msg) nil end end rescue failed_to_log("Unable to verify #{msg}. '#{$!}'") end |
#select_list_includes?(browser, how, what, option, desc = '') ⇒ Boolean Also known as: validate_select_list_contains, select_list_contains?
Verify that a select list, identified by the value (what) in attribute how, contains an option with the value in option.
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/awetestlib/regression/validations.rb', line 440 def select_list_includes?(browser, how, what, option, desc = '') msg = ("Select list #{how}=>#{what} includes option '#{option}'.", desc) select_list = browser.select_list(how, what) = select_list. if option if .include?(option) passed_to_log(msg) true else failed_to_log(msg) end end rescue failed_to_log("Unable to verify #{msg}. '#{$!}'") end |
#set?(browser, how, what, desc = '', no_fail = false) ⇒ Boolean Also known as: radio_set?, radio_checked?, radio_selected?
Verify that a radio button is set.
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/awetestlib/regression/validations.rb', line 356 def set?(browser, how, what, desc = '', no_fail = false) #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set? msg = ("Radio #{how}=>#{what} is selected.", desc) if browser.radio(how, what).set? passed_to_log(msg) true else if no_fail passed_to_log("Radio #{how}=>#{what} is not selected.") else failed_to_log(msg) end end rescue failed_to_log("Unable to verify taht #{msg}: '#{$!}'") end |
#string_contains?(strg, target, desc = '') ⇒ Boolean Also known as: validate_string, validate_string_contains
993 994 995 996 997 998 999 1000 1001 |
# File 'lib/awetestlib/regression/validations.rb', line 993 def string_contains?(strg, target, desc = '') msg = ("String '#{strg}' contains '#{target}'.", desc) if strg.match(target) passed_to_log("#{msg} (#{__LINE__})") true else failed_to_log("#{msg} (#{__LINE__})") end end |
#string_does_not_contain?(strg, target, desc = '') ⇒ Boolean Also known as: validate_string_not_contains, validate_string_not_contain, validate_string_does_not_contain
1006 1007 1008 1009 1010 1011 1012 1013 1014 |
# File 'lib/awetestlib/regression/validations.rb', line 1006 def string_does_not_contain?(strg, target, desc = '') msg = ("String '#{strg}' does not contain '#{target}'.", desc) if strg.match(target) failed_to_log("#{msg} (#{__LINE__})") true else passed_to_log("#{msg} (#{__LINE__})") end end |
#string_does_not_equal?(actual, expected, desc = '') ⇒ Boolean Also known as: validate_string_not_equal, validate_string_does_not_equal
Compare strings for no match and log results
505 506 507 508 509 510 511 512 513 |
# File 'lib/awetestlib/regression/validations.rb', line 505 def string_does_not_equal?(actual, expected, desc = '') msg = ("Actual string '#{actual}' does not equal expected '#{expected}'.", desc) if actual == expected failed_to_log("#{msg} (#{__LINE__})") true else passed_to_log("#{msg} (#{__LINE__})") end end |
#string_equals?(actual, expected, desc = '') ⇒ Boolean Also known as: validate_string_equal, validate_string_equals, text_equals, text_equals?
Compare strings for exact match and log results
485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/awetestlib/regression/validations.rb', line 485 def string_equals?(actual, expected, desc = '') msg = ("Actual string '#{actual}' equals expected '#{expected}'.", desc) if actual == expected passed_to_log("#{msg}") true else failed_to_log("#{msg}") end rescue failed_to_log("Unable to #{msg}. #{$!}") end |
#text_in_element_equals?(browser, element, how, what, expected, desc = '') ⇒ Boolean
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/awetestlib/regression/validations.rb', line 839 def text_in_element_equals?(browser, element, how, what, expected, desc = '') msg = ("Expected exact text '#{expected}' in #{element} :#{how}=>#{what}.", desc) text = '' who = browser.element(how, what) if who text = who.text if text == expected passed_to_log(msg) true else debug_to_log("exp: [#{expected.gsub(' ', '^')}]") debug_to_log("act: [#{text.gsub(' ', '^')}]") failed_to_log("#{msg} Found '#{text}'.") end end rescue failed_to_log("Unable to verify #{msg} '#{$!}'") end |
#textfield_contains?(browser, how, what, expected, desc = '') ⇒ Boolean
Verify that a text field (also text area), identified by how and what, contains the string specified in expected.
650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/awetestlib/regression/validations.rb', line 650 def textfield_contains?(browser, how, what, expected, desc = '') msg = ("Text field #{how}=>#{what} contains '#{expected}'.", desc) contents = browser.text_field(how, what).value if contents =~ /#{expected}/ passed_to_log(msg) true else failed_to_log("#{msg} Contents: '#{contents}'") end rescue failed_to_log("Unable to verify that #{msg} '#{$!}'") end |
#textfield_does_not_equal?(browser, how, what, expected, desc = '') ⇒ Boolean Also known as: validate_textfield_not_value
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/awetestlib/regression/validations.rb', line 1042 def textfield_does_not_equal?(browser, how, what, expected, desc = '') msg = ("Text field #{how}=>#{what} does not equal '#{expected}'", desc) if not browser.text_field(how, what).value == expected passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log("Unable to validate that #{msg}: '#{$!}'") end |
#textfield_empty?(browser, how, what, desc = '') ⇒ Boolean Also known as: validate_textfield_empty, text_field_empty?
Verify that a text field (also text area), identified by how and what, is empty.
671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/awetestlib/regression/validations.rb', line 671 def textfield_empty?(browser, how, what, desc = '') msg = "Text field #{how}=>#{what} is empty." msg << desc if desc.length > 0 contents = browser.text_field(how, what).value if contents.to_s.length == 0 passed_to_log(msg) true else failed_to_log("#{msg} Contents: '#{contents}'") end rescue failed_to_log("Unable to verify that #{msg} '#{$!}'") end |
#textfield_equals?(browser, how, what, expected, desc = '') ⇒ Boolean Also known as: validate_textfield_value, text_field_equals?
Verify that a text field (also text area), identified by how and what, contains only the exact string specified in expected.
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/awetestlib/regression/validations.rb', line 610 def textfield_equals?(browser, how, what, expected, desc = '') msg = ("Expected value to equal '#{expected}' in textfield #{how}=>'#{what}'.", desc) actual = browser.text_field(how, what).value if actual.is_a?(Array) actual = actual[0].to_s end if actual == expected passed_to_log(msg) true else act_s = actual.strip exp_s = expected.strip if act_s == exp_s passed_to_log("#{msg} (stripped)") true else debug_to_report( "#{__method__} (spaces underscored):\n "+ "expected:[#{expected.gsub(' ', '_')}] (#{expected.length})\n "+ "actual:[#{actual.gsub(' ', '_')}] (#{actual.length}) (spaces underscored)" ) failed_to_log("#{msg}. Found: '#{actual}'") end end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}") end |
#validate_list_by_id(browser, what, option, desc = '', select_if_present = true) ⇒ Object
Verify that select list, identified by the value what in the attribute :id, contains text and select it if present.
782 783 784 785 786 787 788 789 790 791 |
# File 'lib/awetestlib/regression/validations.rb', line 782 def validate_list_by_id(browser, what, option, desc = '', select_if_present = true) if select_list_includes?(browser, :id, what, option, desc) if select_if_present select_option(browser, :id, what, :text, option, desc, false) else passed_to_log() true end end end |
#validate_list_by_name(browser, what, option, desc = '', select_if_present = true) ⇒ Object
Verify that select list contains text
794 795 796 797 798 799 800 801 802 803 |
# File 'lib/awetestlib/regression/validations.rb', line 794 def validate_list_by_name(browser, what, option, desc = '', select_if_present = true) if select_list_includes?(browser, :name, what, option, desc) if select_if_present select_option(browser, :name, what, :text, option, desc, false) else passed_to_log() true end end end |
#validate_message(browser, message) ⇒ Object
Use #message_to_log
1065 1066 1067 |
# File 'lib/awetestlib/regression/validations.rb', line 1065 def (browser, ) () end |
#validate_no_text(browser, ptrn, desc = '') ⇒ Object
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
# File 'lib/awetestlib/regression/validations.rb', line 1020 def validate_no_text(browser, ptrn, desc = '') cls = browser.class.to_s cls.gsub!('Watir::', '') cls.gsub!('IE', 'Browser') msg = "#{cls} does not contain text '#{ptrn}'." msg << " #{desc}" if desc.length > 0 if ptrn.is_a?(Regexp) target = ptrn else target = Regexp.new(Regexp.escape(ptrn)) end browser_text = browser.text if browser_text.match(target) failed_to_log("#{msg} [#{browser_text.match(target)[0]}]") else passed_to_log(msg) true end rescue failed_to_log("Unable to verify that #{msg}: '#{$!}'") end |
#validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5) ⇒ Object
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'lib/awetestlib/regression/validations.rb', line 893 def validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5) mark_testlevel("#{__method__.to_s.titleize} (#{how}=>#{what})", 0) ok = true select_list = browser.select_list(how, what) = select_list. if list if == list passed_to_log("Select list options list equals expected list #{list}") else debug_to_report("actual:\n#{nice_array(, true)}") debug_to_report("expected:\n#{nice_array(list, true)}") failed_to_log("Select list options list #{nice_array(, true)} "+ "does not equal expected list #{nice_array(list, true)}") end end #single selections cnt = 0 .each do |opt| if not ignore.include?(opt) cnt += 1 ok = select_option(select_list, opt_type, opt) break if not ok select_list.clear break if limit > 0 and cnt >= limit end end sleep_for(0.5) select_list.clear if ok and multiple if .length > 2 targets = list.slice(1, 2) select_option(select_list, opt_type, [1]) select_option(select_list, opt_type, [2]) selected = select_list. if selected == targets passed_to_log("Select list selected options equals expected #{targets}") else failed_to_log("Select list selected options #{selected} does not equal expected list #{targets.to_a}") end else debug_to_log("Too few options to test multiple selection (need 2 or more): '#{}", __LINE__) end end rescue failed_to_log("Unable to validate select_list: '#{$!}'", __LINE__) end |
#validate_select_list_contents(browser, how, what, list) ⇒ Object
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/awetestlib/regression/validations.rb', line 942 def validate_select_list_contents(browser, how, what, list) mark_testlevel("#{__method__.to_s.titleize} (#{what})", 2) select_list = browser.select_list(how, what) = select_list. if list if == list passed_to_log("Select list options list equals expected list #{list}") else failed_to_log("Select list options list #{} does not equal expected list #{list}") nil end end rescue failed_to_log("Unable to validate select_list contents: '#{$!}'", __LINE__) end |
#validate_selected_options(browser, how, what, list, desc = '') ⇒ Object Also known as: validate_selections, validate_select_list_selections
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'lib/awetestlib/regression/validations.rb', line 959 def (browser, how, what, list, desc = '') select_list = browser.select_list(how, what) selected = select_list..sort if list.is_a?(Array) if selected == list.sort passed_to_log("Expected options [#{list.sort}] are selected [#{selected}]. #{desc}") else failed_to_log("Selected options [#{selected}] do not match expected [#{list.sort}]. #{desc}") true end else if selected.length == 1 if selected[0] =~ /#{list}/ passed_to_log("Expected option [#{list}] was selected. #{desc}") true else failed_to_log("Expected option [#{list}] was not selected. Found [#{selected}]. #{desc}") end else if selected.include?(list) failed_to_log("Expected option [#{list}] was found among multiple selections [#{selected}]. #{desc}") else failed_to_log("Expected option [#{list}] was not found among multiple selections [#{selected}]. #{desc}") end end end rescue failed_to_log("Unable to validate selected option(s): '#{$!}' #{desc}", __LINE__) end |
#validate_style_greater_than_value(browser, element, how, what, type, value, desc = '') ⇒ Object Also known as: validate_style_greaterthan_value
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/awetestlib/regression/validations.rb', line 52 def validate_style_greater_than_value(browser, element, how, what, type, value, desc = '') case element when :link actual_value = browser.link(how => what).style type when :button actual_value = browser.(how => what).style type when :image actual_value = browser.image(how => what).style type when :span actual_value = browser.span(how => what).style type when :div actual_value = browser.div(how => what).style type else actual_value = browser.element(how => what).style type end msg = ("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc) if actual_value.to_i > value.to_i passed_to_log(msg) elsif actual_value.to_i >~ value.to_i passed_to_log(msg) else failed_to_log(msg) end rescue fail_to_log("Unable to verify #{msg} '#{$!}'") # sleep_for(1) end |
#validate_style_less_than_value(browser, element, how, what, type, value, desc = '') ⇒ Object Also known as: validate_style_lessthan_value
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/awetestlib/regression/validations.rb', line 83 def validate_style_less_than_value(browser, element, how, what, type, value, desc = '') case element when :link actual_value = browser.link(how => what).style type when :button actual_value = browser.(how => what).style type when :image actual_value = browser.image(how => what).style type when :span actual_value = browser.span(how => what).style type when :div actual_value = browser.div(how => what).style type else actual_value = browser.element(how => what).style type end msg = ("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc) if actual_value.to_i < value.to_i passed_to_log(msg) elsif actual_value.to_i <~ value.to_i passed_to_log(msg) else failed_to_log(msg) end rescue fail_to_log("Unable to verify #{msg} '#{$!}'") # sleep_for(1) end |
#validate_style_value(browser, element, how, what, type, expected, desc = '') ⇒ Boolean
Verify that element style attribute contains expected value in style type.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/awetestlib/regression/validations.rb', line 21 def validate_style_value(browser, element, how, what, type, expected, desc = '') #TODO: works only with watir-webdriver msg = ("Expected Style #{type} value '#{expected}' in #{element} with #{how} = #{what}", desc) case element when :link actual = browser.link(how => what).style type when :button actual = browser.(how => what).style type when :image actual = browser.image(how => what).style type when :span actual = browser.span(how => what).style type when :div actual = browser.div(how => what).style type else if browser.element(how => what).responds_to?("style") actual = browser.element(how => what).style type else failed_to_log("#{msg}: Element #{element} does not repond to style command.") end end if expected == actual passed_to_log(msg) true else failed_to_log(msg) end rescue failed_to_log("Unable to verify that #{msg} '#{$!}'") end |
#validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false) ⇒ Object Also known as: validate_link
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/awetestlib/regression/validations.rb', line 805 def validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false) cls = browser.class.to_s cls.gsub!('Watir::', '') cls.gsub!('IE', 'Browser') msg = ("#{cls} text contains '#{ptrn}'.", desc) if ptrn.is_a?(Regexp) target = ptrn else target = Regexp.new(Regexp.escape(ptrn)) end sleep_for(2) unless skip_sleep myText = browser.text if not myText.match(target) sleep_for(2) unless skip_sleep #TODO try a wait_until here? myText = browser.text end if myText.match(target) #if myText.match(ptrn) passed_to_log("#{msg}") true else if skip_fail debug_to_log("#{cls} text does not contain the text: '#{ptrn}'. #{desc}") else failed_to_log("#{msg}") end #debug_to_log("\n#{myText}") end rescue failed_to_log("Unable to verify that #{msg} '#{$!}'") end |
#validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '') ⇒ Boolean
Verify that a text field (also text area), identified by how and what, contains the string specified in expected.
697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/awetestlib/regression/validations.rb', line 697 def validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '') target = expected.dup desc << " Dollar formatting" if with_cents target << '.00' if not expected =~ /\.00$/ desc << " without cents. orig:(#{expected})" else target.gsub!(/\.00$/, '') desc << " with cents. orig:(#{expected})" end textfield_equals?(browser, how, what, target, desc) end |
#validate_url(browser, url, desc = '') ⇒ Boolean
Verify that browser is set to a url that is matched by the string or rexexp in url.
715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/awetestlib/regression/validations.rb', line 715 def validate_url(browser, url, desc = '') msg = ("Current URL matches #{url}.", desc) if browser.url.to_s.match(url) passed_to_log(msg) true else failed_to_log("#{msg} Actual: #{browser.url}") end rescue failed_to_log("Unable to validate that #{msg} '#{$!}'") end |
#visible?(browser, element, how, what, desc = '') ⇒ Boolean Also known as: validate_visible
Verify that a DOM element is visible.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/awetestlib/regression/validations.rb', line 201 def visible?(browser, element, how, what, desc = '') #TODO: handle identification of element with value as well as other attribute. see exists? msg = ("#{element.to_s.titlecase} #{how}=>'#{what}' is visible.", desc) rtrn = false case how when :index target = get_element(browser, element, how, what) if target.visible? rtrn = true end else if browser.element(how, what).visible? rtrn = true end end if rtrn passed_to_log("#{msg}") else failed_to_log("#{msg}") end rtrn rescue failed_to_log("Unable to verify that #{msg}': '#{$!}'") end |
#window_does_not_exist?(title) ⇒ Boolean Also known as: window_no_exists
743 744 745 746 747 748 749 750 751 |
# File 'lib/awetestlib/regression/validations.rb', line 743 def window_does_not_exist?(title) title = translate_popup_title(title) if @ai.WinExists(title) == 1 failed_to_log("Window title:'#{title}' exists") else passed_to_log("Window title:'#{title}' does not exist") true end end |
#window_exists?(title) ⇒ Boolean Also known as: window_exists
731 732 733 734 735 736 737 738 739 |
# File 'lib/awetestlib/regression/validations.rb', line 731 def window_exists?(title) title = translate_popup_title(title) if @ai.WinExists(title) == 1 passed_to_log("Window title:'#{title}' exists") true else failed_to_log("Window title:'#{title}' does not exist") end end |