Module: Awetestlib::Regression::Validations

Includes:
W3CValidators
Defined in:
lib/awetestlib/regression/validations.rb,
lib/awetestlib/regression/awetest_dsl.rb

Overview

Contains methods to verify content, accessibility, or appearance of page elements.

Core collapse

AutoIT collapse

Deprecated collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

Deprecated.


1290
1291
1292
# File 'lib/awetestlib/regression/validations.rb', line 1290

def self.included(mod)
  # puts "RegressionSupport::Validations extended by #{mod}"
end

Instance Method Details

#annotate_html_message(out, location, line, column) ⇒ Object



2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2103

def annotate_html_message(out, location, line, column)
  if location[:script]
    out << " (in script #{line}/#{column})"
  else
    if location[:head]
      out << " (in head)"
      if location[:meta]
        out << " (in meta)"
      end
    end
  end
  if location[:in_frame]
    out << " (in frame)"
  end
  # out << " (in meta)" if in_meta
  # out << " (in body)" if in_body
  if location[:fragment]
    out << " (in fragment)"
  end
end

#array_does_not_include?(array, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1078

def array_does_not_include?(array, expected, desc = '', refs = '')
  msg = build_message(desc, "Array does not include '#{expected}'?", refs)
  if array.include?(expected)
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#array_includes?(array, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1066

def array_includes?(array, expected, desc = '', refs = '')
  msg = build_message(desc, "Array includes '#{expected}'?", refs)
  if array.include?(expected)
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#arrays_match?(exp, act, dir, col, org = nil, desc = '') ⇒ Boolean Also known as: arrays_match

TODO:

Clarify and rename

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/awetestlib/regression/validations.rb', line 115

def arrays_match?(exp, act, desc = '', refs = '')
  msg = build_message(desc, 'Arrays match?', refs)
  exp = exp.is_a?(Array) ? exp.dup : [exp]
  act = act.is_a?(Array) ? act.dup : [act]
  if exp == act
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_contains?(container, element, how, what, attr_name, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1106

def attribute_contains?(container, element, how, what, attribute, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", ";#{attribute}", "contains '#{expected}'?", refs)
  actual = container.element(how, what).attribute_value(attribute)
  if actual
    if actual.match(expected)
      passed_to_log(msg)
      true
    else
      failed_to_log(msg)
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_does_not_contain?(container, element, how, what, attr_name, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1123

def attribute_does_not_contain?(container, element, how, what, attribute, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", "attribute '#{attribute}", "does not contain '#{expected}'?", refs)
  actual = container.element(how, what).attribute_value(attribute)
  if actual
    if actual.match(expected)
      failed_to_log(msg)
    else
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_does_not_equal?(container, element, how, what, attr_name, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1157

def attribute_does_not_equal?(container, element, how, what, attribute, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", "attribute '#{attribute}", "does not equal '#{expected}?", refs)
  actual = container.element(how, what).attribute_value(attribute)
  if actual
    if actual == expected
      failed_to_log(msg)
    else
      passed_to_log("#{msg} Found '#{actual}'")
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_does_not_exist?(container, how, what, attribute, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1315
1316
1317
1318
1319
1320
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1315

def attribute_does_not_exist?(container, how, what, attribute, desc = '', refs = '')
  target = container.element(how, what)
  element_attribute_does_not_exist?(target, attribute, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_equals?(container, element, how, what, attr_name, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1140

def attribute_equals?(container, element, how, what, attribute, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", "attribute '#{attribute}", "equals '#{expected}'?", refs)
  actual = container.element(how, what).attribute_value(attribute)
  if actual
    if actual == expected
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_exists?(container, how, what, attribute, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1293
1294
1295
1296
1297
1298
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1293

def attribute_exists?(container, how, what, attribute, desc = '', refs = '')
  target = container.element(how, what)
  element_attribute_exists?(target, attribute, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_in_html?(container, how, what, attribute, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1248
1249
1250
1251
1252
1253
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1248

def attribute_in_html?(container, how, what, attribute, desc = '', refs = '')
  target = container.element(how, what)
  element_attribute_in_html?(target, attribute, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#attribute_not_in_html?(container, how, what, attribute, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1271
1272
1273
1274
1275
1276
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1271

def attribute_not_in_html?(container, how, what, attribute, desc = '', refs = '')
  target = container.element(how, what)
  element_attribute_not_in_html?(target, attribute, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#boolean_equals?(actual, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1703

def boolean_equals?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Boolean '#{actual}' equals expected '#{expected}'?", refs)
  if actual == expected
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#border_colors_equal?(container, element, how, what, desc, refs, *colors) ⇒ Boolean

Returns:

  • (Boolean)


2932
2933
2934
2935
2936
2937
2938
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2932

def border_colors_equal?(container, element, how, what, desc, refs, *colors)
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  element_border_colors_equal?(target, how, what, desc, refs, *colors)
rescue
  rescue_msg_for_validation(desc, refs)
end

#border_sizes_equal?(container, element, how, what, attribute, desc, refs, *pixels) ⇒ Boolean

Returns:

  • (Boolean)


2969
2970
2971
2972
2973
2974
2975
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2969

def border_sizes_equal?(container, element, how, what, attribute, desc, refs, *pixels)
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  element_border_sizes_equal?(target, how, what, attribute, desc, refs, *pixels)
rescue
  rescue_msg_for_validation(desc, refs)
end

#borders_equal?(container, element, how, what, desc, refs, *pixels) ⇒ Boolean

Returns:

  • (Boolean)


3007
3008
3009
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3007

def borders_equal?(container, element, how, what, desc, refs, *pixels)
  border_sizes_equal?(container, element, how, what, 'borders', desc, refs, *pixels)
end

#checkbox_does_not_have_checked?(checkbox, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1235

def checkbox_does_not_have_checked?(checkbox, desc = '', refs = '')
  msg  = element_query_message(checkbox, "does not have 'checked' attribute", nil, nil, nil, desc, refs)
  html = checkbox.html
  if html =~ /checked=""/ or not html =~ /checked/
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#checkbox_has_checked?(checkbox, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1222

def checkbox_has_checked?(checkbox, desc = '', refs = '')
  msg  = element_query_message(checkbox, "has 'checked' attribute", nil, nil, nil, desc, refs)
  html = checkbox.html
  if html =~ /checked/ and not html =~ /checked=""/
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#checkbox_not_checked?Boolean

Returns:

  • (Boolean)


1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1207

def not_checked?(container, how, what, value = nil, desc = '', refs = '')
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_checked?(target, desc, refs, how, what, value)
rescue
  rescue_msg_for_validation(desc, refs)
end

#checkbox_not_set?Boolean

Returns:

  • (Boolean)


1208
1209
1210
1211
1212
1213
1214
1215
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1208

def not_checked?(container, how, what, value = nil, desc = '', refs = '')
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_checked?(target, desc, refs, how, what, value)
rescue
  rescue_msg_for_validation(desc, refs)
end

#checked?(browser, how, what, desc = '') ⇒ Boolean Also known as: checkbox_checked?, checkbox_set?

Verify that a checkbox is checked.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the checkbox is checked.



340
341
342
343
344
345
346
347
# File 'lib/awetestlib/regression/validations.rb', line 340

def checked?(container, element, how, what, value = nil, desc = '', refs = '')
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_checked?(target, desc, refs, how, what, value)
rescue
  rescue_msg_for_validation(desc, refs)
end

#class_contains?(container, element, how, what, expected, desc = '', refs = '') ⇒ Boolean Also known as: verify_class

Returns:

  • (Boolean)


1016
1017
1018
1019
1020
1021
1022
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1016

def class_contains?(container, element, how, what, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_class_contains?(target, expected, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what), false, true))
end

#class_does_not_contain?(container, element, how, what, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


995
996
997
998
999
1000
1001
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 995

def class_does_not_contain?(container, element, how, what, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_class_does_not_contain?(target, expected, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what), false, true))
end

#class_equals?(container, element, how, what, expected, desc = '', refs = '') ⇒ Boolean

def centered?(container, element, desc = ”, refs = ”)

name                      = element.respond_to?(:tag_name) ? element.tag_name.upcase : 'DOM'
msg                       = build_message(desc, "is centered @@@?", refs)

element_x, element_y      = element.dimensions
element_left, element_top = element.client_offset

horizontally = (((element_left * 2) + element_x.floor).to_i) == viewport_x
h_msg        = msg.sub('@@@', 'horizontally')
if horizontally
  passed_to_log(h_msg)
else
  failed_to_log(h_msg)
end

# At <= 600BP, should be full size of viewport
vertically = true
unless element_top <= 1 || element_x <= 601
  vertically = ((element_top * 2) + element_y) == viewport_y
  v_msg      = msg.sub('@@@', 'vertically')

  if vertically
    passed_to_log(v_msg)
  else
    failed_to_log(v_msg)
  end
end

if horizontally and vertically
  true
else
  false
end

rescue

failed_to_log(unable_to(msg.sub('@@@ ', ''), false, true))

end

Returns:

  • (Boolean)


974
975
976
977
978
979
980
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 974

def class_equals?(container, element, how, what, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_class_equals?(target, expected, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what), false, true))
end

#columns_match?(exp, act, dir, col, org = nil, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1041

def columns_match?(exp, act, dir, col, org = nil, desc = '', refs = '')
  msg = build_message(desc, "Click on #{dir} column '#{col}' produces expected sorted list?", refs)
  ok  = arrays_match?(exp, act, msg)
  unless ok
    debug_to_log("Original order ['#{org.join("', '")}']") if org
    debug_to_log("Expected order ['#{exp.join("', '")}']")
    debug_to_log("  Actual order ['#{act.join("', '")}']")
  end
  ok
rescue
  rescue_msg_for_validation(desc, refs)
end

#contains_text?(container, element, how, what, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1608

def contains_text?(container, element, how, what, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}' contains '#{expected}'?", refs)
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  if target
    element_wait(target)
    if target.text.match(expected)
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{text}'. #{desc}")
    end
  end
rescue
  rescue_msg_for_validation(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 even though the dates/times match

Parameters:

  • fail_on_format (Boolean) (defaults to: true)

    If set to true method will fail if the formats differ

  • actual (String)

    The actual value as found in the application.

  • expected (String)

    The value expected to be found.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if actual does not match expected.



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/awetestlib/regression/validations.rb', line 600

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 = build_message("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

#dimension_within_tolerance?(name, actual, expected, tolerance, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


932
933
934
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 932

def dimension_within_tolerance?(name, actual, expected, tolerance, desc = '', refs = '')
  within_tolerance?(actual, expected, tolerance, with_caller("#{desc}, Dimension", name), refs = '')
end

#dimensions_equal?(first_name, first_value, second_name, second_value, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


908
909
910
911
912
913
914
915
916
917
918
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 908

def dimensions_equal?(first_name, first_value, second_name, second_value, desc = '', refs = '')
  msg = build_message(desc, "#{first_name}: #{first_value} equals #{second_name}: #{second_value}?", refs)
  if first_value == second_value
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#dimensions_not_equal?(first_name, first_value, second_name, second_value, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


920
921
922
923
924
925
926
927
928
929
930
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 920

def dimensions_not_equal?(first_name, first_value, second_name, second_value, desc = '', refs = '')
  msg = build_message(desc, "#{first_name}: #{first_value} does not equal #{second_name}: #{second_value}?", refs)
  if first_value == second_value
    failed_to_log("#{msg}")
  else
    passed_to_log("#{msg}")
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#directory_exists?(directory) ⇒ Boolean

Returns:

  • (Boolean)


1676
1677
1678
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1676

def directory_exists?(directory)
  File.directory?(directory)
end

#disabled?(container, element, how, what, desc = '', value = nil) ⇒ Boolean Also known as: validate_not_enabled, validate_disabled

Verify that a DOM element is disabled.

Returns:

  • (Boolean)

    Returns true if the element is disabled.



192
193
194
195
196
197
198
199
# File 'lib/awetestlib/regression/validations.rb', line 192

def disabled?(container, element, how, what, desc = '', value = nil, refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_disabled?(target, desc, refs, how, what, value)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, value), false, true))
end

#disablement(container, should_be, element, how, what, desc = '') ⇒ Object



2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2657

def disablement(container, boolean, element, how, what, desc = '', refs = '')
  should_be = force_boolean(boolean)
  if should_be
    disabled?(container, element, how, what, desc, nil, refs)
  else
    enabled?(container, element, how, what, desc, nil, refs)
  end
rescue
  failed_to_log(unable_to(desc, false, true))
end

#does_not_contain_text?(container, element, how, what, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1625

def does_not_contain_text?(container, element, how, what, expected, desc = '', refs = '')
  msg    = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}' does not contain '#{expected}'?", refs)
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  if target
    element_wait(target)
    if target.text.match(expected)
      failed_to_log("#{msg} Found '#{text}'. #{desc}")
    else
      passed_to_log(msg)
      true
    end
  end
rescue
  rescue_msg_for_validation(msg)
end

#does_not_exist?(container, element, how, what, value = nil, desc = '') ⇒ Boolean Also known as: not_exist?

Verify that a DOM element does not exist on the page.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • value (String, Regexp) (defaults to: nil)

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the element does not exist.



412
413
414
415
416
417
418
419
# File 'lib/awetestlib/regression/validations.rb', line 412

def does_not_exist?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_does_not_exist?(target, value, desc, refs, how, what, element)
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_contains?(element, attribute, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1400

def element_attribute_contains?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil)
  msg    = element_query_message(element, "attribute '#{attribute}' contains '#{force_string(expected)}'?", how, what, nil, desc, refs)
  actual = element.attribute_value(attribute)
  if actual
    if actual.match(expected)
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_attribute_does_not_contain?(element, attribute, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1417

def element_attribute_does_not_contain?(element, attribute, expected, desc = '', refs = '')
  msg    = element_query_message(element, "attribute '#{attribute}' does not contain '#{force_string(expected)}'?", nil, nil, nil, desc, refs)
  actual = element.attribute_value(attribute)
  if actual
    if actual.match(expected)
      msg << " Found '#{actual.match(expected)[1]}'"
      failed_to_log(msg)
    else
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_attribute_does_not_equal?(element, attr_name, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1381

def element_attribute_does_not_equal?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil)
  msg    = element_query_message(element, "attribute '#{attribute}' does not equal '#{force_string(expected)}'?", how, what, nil, desc, refs)
  actual = element.attribute_value(attribute)
  if actual
    if actual == expected
      failed_to_log(msg)
    else
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_does_not_exist?(element, attribute, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1322

def element_attribute_does_not_exist?(element, attribute, desc = '', refs = '', how = nil, what = nil)
  msg  = element_query_message(element, "attribute '#{attribute}' does not exist?", how, what, nil, desc, refs)
  # element_wait(element)
  ptrn = /(?:<|\s)#{attribute}(?:\s|>|=|$)/
  if element.html =~ ptrn
    value = element.attribute_value(attribute)
    failed_to_log("#{msg} '#{attribute}' found with value '#{value}'.")
  else
    passed_to_log("#{msg}")
    true
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_equals?(element, attr_name, expected, desc = '') ⇒ Boolean

def element_inline_attribute_equals?(element, attribute, expected, desc = ”, refs = ”)

element_html = element.html
if element_html.include? attribute
  inline_attr = "#{attribute}" + '=' + '"' + "#{value}" + '"'
  puts inline_attr
  if element_html.include? inline_attr
    pass_to_log("#{attribute} has the expected value of #{value}")
  else
    fail_to_log("#{attribute} missing the expected value of #{value} ")
  end
end

end

Returns:

  • (Boolean)


1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1364

def element_attribute_equals?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil)
  msg    = element_query_message(element, "attribute '#{attribute}' equals '#{force_string(expected)}'?", how, what, nil, desc, refs)
  actual = element.attribute_value(attribute)
  if actual
    if actual == expected
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_exists?(element, attribute, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1300

def element_attribute_exists?(element, attribute, desc = '', refs = '', how = nil, what = nil)
  msg  = element_query_message(element, "attribute '#{attribute}' exists?", how, what, nil, desc, refs)
  # element_wait(element)
  ptrn = /(?:<|\s)#{attribute}(?:\s|>|=|$)/
  if element.html =~ ptrn
    value = element.attribute_value(attribute)
    passed_to_log("#{msg} '#{attribute}' found with value '#{value}'.")
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_greater?(element, attr_name, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1435

def element_attribute_greater?(element, attr_name, expected, desc = '', refs = '')
  msg    = element_query_message(element, "attribute '#{attr_name}' greater than '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.attribute_value(attr_name)
  if actual
    if actual.to_i > expected.to_i
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_greater_or_equal?(element, attr_name, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1469

def element_attribute_greater_or_equal?(element, attr_name, expected, desc = '', refs = '')
  msg    = element_query_message(element, "attribute '#{attr_name}' greater than or equal to '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.attribute_value(attr_name)
  if actual
    if actual.to_i >= expected.to_i
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_in_html?(element, attribute, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1255

def element_attribute_in_html?(element, attribute, desc = '', refs = '', how = nil, what = nil)
  msg  = element_query_message(element, "attribute '#{attribute}' exists in html?", how, what, nil, desc, refs)
  # element_wait(element)
  ptrn = /#{attribute}(?:\s|>|=|$)/
  # debug_to_log(with_caller("[#{element.html}]::", "[#{ptrn}"))
  if element.html =~ ptrn
    attr_vlu = element.attribute_value(attribute)
    passed_to_log("#{msg} Value = '#{attr_vlu}'")
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_less?(element, attr_name, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1452

def element_attribute_less?(element, attr_name, expected, desc = '', refs = '')
  msg    = element_query_message(element, "attribute '#{attr_name}' less than '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.attribute_value(attr_name)
  if actual
    if actual.to_i < expected.to_i
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_less_or_equal?(element, attr_name, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1486

def element_attribute_less_or_equal?(element, attr_name, expected, desc = '', refs = '')
  msg    = element_query_message(element, "attribute '#{attr_name}' less than or equal to '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.attribute_value(attr_name)
  if actual
    if actual.to_i <= expected.to_i
      passed_to_log(msg)
      true
    else
      failed_to_log("#{msg} Found '#{actual}'")
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_not_equal?Boolean

Returns:

  • (Boolean)


1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1398

def element_attribute_does_not_equal?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil)
  msg    = element_query_message(element, "attribute '#{attribute}' does not equal '#{force_string(expected)}'?", how, what, nil, desc, refs)
  actual = element.attribute_value(attribute)
  if actual
    if actual == expected
      failed_to_log(msg)
    else
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_attribute_not_in_html?(element, attribute, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1278

def element_attribute_not_in_html?(element, attribute, desc = '', refs = '', how = nil, what = nil)
  msg  = element_query_message(element, "attribute '#{attribute}' does not exist in html?", how, what, nil, desc, refs)
  ptrn = /#{attribute}(?:\s|>|=|$)/
  # debug_to_log(with_caller("[#{element.html}]::", "[#{ptrn}"))
  if element.html =~ ptrn
    attr_vlu = element.attribute_value(attribute)
    failed_to_log("#{msg} Value = '#{attr_vlu}'")
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_border_colors_equal?(element, how, what, desc, refs, *colors) ⇒ Boolean

Returns:

  • (Boolean)


2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2940

def element_border_colors_equal?(element, how, what, desc, refs, *colors)
  msg    = element_query_message(element, "Border colors are '#{colors}'?", how, what, nil, desc, refs)
  errors = 0
  errs   = []

  sides = ['top', 'bottom', 'left', 'right']
  sides.each do |side|
    idx      = sides.index(side)
    color    = colors[idx] ? colors[idx] : colors[0]
    expected = normalize_color_value(color)
    debug_to_log(with_caller(desc, side, 'expected normalized:', expected))
    actual = normalize_color_value(element.style("border-#{side}-color"))
    unless actual == expected
      errors += 1
      errs << "#{side}:#{actual}"
    end
  end

  if errors == 0
    passed_to_log(with_caller(msg))
    true
  else
    failed_to_log(with_caller(msg, "Found #{nice_array(errs)}"))
  end

rescue
  rescue_msg_for_validation(msg)
end

#element_border_sizes_equal?(element, how, what, attribute, desc, refs, *pixels) ⇒ Boolean

Returns:

  • (Boolean)


2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2977

def element_border_sizes_equal?(element, how, what, attribute, desc, refs, *pixels)
  attribute = attribute.downcase.gsub(/s$/, '')
  errors    = 0

  sides = ['top', 'bottom', 'left', 'right']

  sides.each do |side|
    msg      = element_query_message(element, "#{attribute}-#{side} equals '#{pixels}'?", how, what, nil, desc, refs)
    idx      = sides.index(side)
    value    = pixels[idx] ? pixels[idx] : pixels[0]
    expected = value =~ /px$/ ? value.to_s : "#{value}px"
    actual   = element.style("#{attribute}-#{side}")
    if actual == expected
      passed_to_log(msg)
    else
      failed_to_log(msg)
      errors += 1
    end
  end

  errors == 0

rescue
  rescue_msg_for_validation(desc, refs)
end

#element_checked?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1186

def element_checked?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, "is checked?", how, what, value, desc, refs)
  if element.checked?
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_class_contains?(element, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1026

def element_class_contains?(element, expected, desc = '', refs = '', how = nil, what = nil)
  msg        = element_query_message(element, ":class contains '#{expected}'?", how, what, nil, desc, refs)
  class_name = element.class_name
  if class_name.match(expected)
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg}. Found '#{class_name}'")
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_class_does_not_contain?(element, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1003

def element_class_does_not_contain?(element, expected, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, ":class does not contain '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.class_name.match(expected)
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_class_equals?(container, element, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


982
983
984
985
986
987
988
989
990
991
992
993
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 982

def element_class_equals?(container, element, expected, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, ":class equals '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.class_name == expected
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg}. Found '#{element.class_name}'")
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_contains_text?(browser, element, how, what, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1642

def element_contains_text?(element, expected, desc = '', refs = '', how = '', what = '', skip_fail = false)
  msg = element_query_message(element, "text contains '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.text.match(expected)
    passed_to_log(msg)
    true
  else
    if skip_fail
      debug_to_log(build_msg(msg, "(Fail suppressed)"))
    else
      failed_to_log("#{msg} Found '#{element.text}'")
    end
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_disabled?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2677

def element_disabled?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, 'is disabled?', how, what, value, desc, refs)
  element_wait(element)
  if element.respond_to?(:disabled?)
    if element.disabled?
      passed_to_log(msg)
      true
    else
      failed_to_log(msg)
    end
  else
    failed_to_log(build_message("#{element} does not respond to .disabled?"), msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_disablement(target, disabled, desc = '') ⇒ Object



2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2720

def element_disablement(target, disabled, desc = '', refs = '')
  #TODO: Is this really necessary?
  is_disabled = target.disabled?
  disablement = false
  should_be   = disabled ? true : false
  msg         = build_message(desc, "(in #{method_to_title(__method__)})", "should be #{should_be}", "is #{is_disabled}", refs)
  if should_be == is_disabled
    passed_to_log(msg)
    disablement = true
  else
    failed_to_log(msg)
  end
  [is_disabled, disablement]
rescue
  rescue_msg_for_validation(msg)
end

#element_does_not_contain_text?(element, expected, desc = '', refs = '', how = '', what = '') ⇒ Boolean Also known as: element_text_does_not_contain?

Returns:

  • (Boolean)


1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1661

def element_does_not_contain_text?(element, expected, desc = '', refs = '', how = '', what = '')
  msg = element_query_message(element, "text does not contain '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.text.match(expected)
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_does_not_exist?(element, value = nil, desc = '', refs = '', how = nil, what = nil, tag = nil) ⇒ Boolean

Returns:

  • (Boolean)


2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2450

def element_does_not_exist?(element, value = nil, desc = '', refs = '', how = nil, what = nil, tag = nil)
  msg = element_query_message(element, 'does not exist?', how, what, value, desc, refs, tag)
  if element.exists?
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_existence(element, should_be, desc = '', refs = '', how = '', what = '') ⇒ Object



2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2409

def element_existence(element, should_be, desc = '', refs = '', how = '', what = '')
  should_be = force_boolean(should_be)
  if should_be
    element_exists?(element, desc, refs, how, what, nil)
  else
    element_does_not_exist?(element, desc, refs, how, what, nil)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_exists?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2429

def element_exists?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, 'exists?', how, what, value, desc, refs)
  if element.exists?
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_focused?(element, how, what, value = nil, desc = '', refs = '') ⇒ Boolean Also known as: element_is_focused?

Returns:

  • (Boolean)


2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2591

def element_focused?(element, how, what, value = nil, desc = '', refs = '')
  msg     = element_query_message(element, 'has focus?', how, what, value, desc, refs)
  current = element.browser.execute_script("return document.activeElement")
  if element == current
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_inline_attribute_contains?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1337

def element_inline_attribute_contains?(element, attribute, expected, desc = '', refs = '', how = nil, what = nil)
  msg          = element_query_message(element, "Inline attribute '#{attribute}' contains '#{force_string(expected)}'?", how, what, nil, desc, refs)
  element_html = element.html
  if element_html.include? attribute
    inline_attr = "#{attribute}" + '=' + '"' + "#{expected}" + '"'
    puts inline_attr
    if element_html.include? inline_attr
      pass_to_log(msg)
    else
      fail_to_log(msg)
    end
  end
end

#element_is_present?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean Also known as: element_present?

Returns:

  • (Boolean)


2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2495

def element_is_present?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, 'is_present?', how, what, value, desc, refs)
  if element.present?
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_not_checked?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1210

def element_not_checked?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, "is not checked?", how, what, value, desc, refs)
  if element.checked?
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_not_disabled?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean Also known as: element_enabled?

Returns:

  • (Boolean)


2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2705

def element_not_disabled?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, 'is enabled?', how, what, value, desc, refs)
  element_wait(element)
  if element.disabled?
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_not_focused?(element, how, what, value = nil, desc = '', refs = '') ⇒ Boolean Also known as: element_is_not_focused?

Returns:

  • (Boolean)


2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2567

def element_not_focused?(element, how, what, value = nil, desc = '', refs = '')
  msg     = element_query_message(element, 'does not have focus?', how, what, value, desc, refs)
  current = element.browser.execute_script("return document.activeElement")
  if element == current
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_not_present?(element, desc = '', refs = '', how = nil, what = nil, value = nil) ⇒ Boolean Also known as: element_is_not_present?

Returns:

  • (Boolean)


2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2518

def element_not_present?(element, desc = '', refs = '', how = nil, what = nil, value = nil)
  msg = element_query_message(element, 'is not present?', how, what, value, desc, refs)
  if element.present?
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_not_visible?(element, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2645

def element_not_visible?(element, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, 'is not visible?', how, what, nil, desc, refs)
  if element.visible?
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_presence(element, should_be, desc = '', refs = '', how = '', what = '') ⇒ Object



2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2475

def element_presence(element, should_be, desc = '', refs = '', how = '', what = '')
  should_be = force_boolean(should_be)
  if should_be
    element_is_present?(element, desc, refs, how, what, nil)
  else
    element_not_present?(element, desc, refs, how, what, nil)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_style_contains?(element, style, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2828

def element_style_contains?(element, style, expected, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, "style '#{style}' contains '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.style(style).match(expected)
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg}. Found '#{element.class_name}'")
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_style_does_not_contain?(element, style, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2807

def element_style_does_not_contain?(element, style, expected, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, "style '#{style}' does not contain '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.style(style).match(expected)
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_style_does_not_equal?(element, style, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean Also known as: element_color_does_not_equal?, element_color_not_equal?, element_style_not_equal?

Returns:

  • (Boolean)


2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2854

def element_style_does_not_equal?(element, style, expected, desc = '', refs = '', how = nil, what = nil)
  msg           = element_query_message(element, "style '#{style}' does not equal '#{expected}'?", how, what, nil, desc, refs)
  actual        = element.style(style)
  actual_norm   = style =~ /color/ ? normalize_color_value(actual) : actual
  expected_norm = style =~ /color/ ? normalize_color_value(expected) : expected

  if actual
    if actual_norm == expected_norm
      failed_to_log(msg)
    else
      found = style =~ /color/ ? "#{rgb_to_html(actual).upcase} (#{actual_norm})" : "#{actual}"
      passed_to_log("#{msg}. Found #{found}")
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end

rescue
  rescue_msg_for_validation(msg)
end

#element_style_equals?(element, style, expected, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean Also known as: element_color_equals?

Returns:

  • (Boolean)


2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2890

def element_style_equals?(element, style, expected, desc = '', refs = '', how = nil, what = nil)
  msg    = element_query_message(element, "style '#{style}' equals '#{expected}'?", how, what, nil, desc, refs)
  actual = element.style(style)
  actual = element.attribute_value(style) unless actual and actual.length > 0
  case style
    when /color/
      actual_norm   = normalize_color_value(actual)
      expected_norm = normalize_color_value(expected)
    when /opacity/
      actual_norm   = actual.to_f
      expected_norm = expected.to_f
    when /border/
      actual_norm   = normalize_border_style(actual)
      expected_norm = normalize_border_style(expected)
    else
      actual_norm   = actual
      expected_norm = expected
  end

  # if style =~ /color/
  #   debug_to_log(with_caller("'#{style}'", "actual:   raw: '" + actual + "'  normalized: '" + actual_norm + "'"))
  #   debug_to_log(with_caller("'#{style}'", "expected: raw: '" + expected + "'  normalized: '" + expected_norm + "'"))
  # end

  if actual and actual.length > 0
    if actual_norm == expected_norm
      passed_to_log(msg)
      true
    else
      found = style =~ /color/ ? "#{rgb_to_html(actual)} (#{actual_norm})" : "#{actual}"
      failed_to_log("#{msg}. Found #{found}")
    end
  else
    failed_to_log("#{msg} '#{style}' not found.")
  end

rescue
  rescue_msg_for_validation(msg)
end

#element_text_contains?Boolean

Returns:

  • (Boolean)


1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1659

def element_contains_text?(element, expected, desc = '', refs = '', how = '', what = '', skip_fail = false)
  msg = element_query_message(element, "text contains '#{expected}'?", how, what, nil, desc, refs)
  element_wait(element)
  if element.text.match(expected)
    passed_to_log(msg)
    true
  else
    if skip_fail
      debug_to_log(build_msg(msg, "(Fail suppressed)"))
    else
      failed_to_log("#{msg} Found '#{element.text}'")
    end
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_text_does_not_include?(element, expected, desc = '', refs = '') ⇒ Boolean Also known as: element_does_not_include_text?

Returns:

  • (Boolean)


1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1579

def element_text_does_not_include?(element, expected, desc = '', refs = '')
  msg    = element_query_message(element, "text does not include '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.text
  if actual
    if actual.include?(expected)
      failed_to_log(msg)
    else
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} '#{attribute}' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_text_includes?(element, expected, desc = '', refs = '') ⇒ Boolean Also known as: element_includes_text?

Returns:

  • (Boolean)


1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1560

def element_text_includes?(element, expected, desc = '', refs = '')
  msg    = element_query_message(element, "text includes '#{expected}'?", nil, nil, nil, desc, refs)
  actual = element.text
  if actual
    if actual.include?(expected)
      passed_to_log(msg)
      true
    else
      failed_to_log(msg)
    end
  else
    failed_to_log("#{msg} 'text' not found.")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#element_value_equals?(element, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1503

def element_value_equals?(element, expected, desc = '', refs = '')
  msg = element_query_message(element, "value equals '#{expected}'?", nil, nil, nil, desc, refs)

  if element.responds_to?('value')
    actual = element.value
    if actual
      if actual == expected
        passed_to_log(msg)
        true
      else
        failed_to_log(msg)
      end
    else
      failed_to_log("#{msg} 'value' not found.")
    end
  else
    failed_to_log("#{msg} Element does not respond to 'value'")
  end

rescue
  rescue_msg_for_validation(desc, refs)
end

#element_visible?(element, desc = '', refs = '', how = nil, what = nil) ⇒ Boolean

Returns:

  • (Boolean)


2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2625

def element_visible?(element, desc = '', refs = '', how = nil, what = nil)
  msg = element_query_message(element, 'is visible?', how, what, nil, desc, refs)
  if element.visible?
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#element_wait(element, sleep = 0.25) ⇒ Object



1598
1599
1600
1601
1602
1603
1604
1605
1606
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1598

def element_wait(element, sleep = 0.25)
  if element.respond_to?(:wait)
    element.wait
  elsif element.respond_to?(:wait_until_present)
    element.wait_until_present
  else
    sleep(sleep)
  end
end

#existence(container, should_be, element, how, what, desc = '') ⇒ Object



2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2396

def existence(container, should_be, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  if should_be
    element_exists?(target, desc, refs, how, what, value)
  else
    element_does_not_exist?(target, desc, refs, how, what, value)
  end
rescue
  failed_to_log(unable_to(desc, false, true))
end

#exists?(container, element, how, what, value = nil, desc = '') ⇒ Boolean

Verify that a DOM element exists on the page.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • value (String, Regexp) (defaults to: nil)

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    True if the element exists.



394
395
396
397
398
399
400
401
# File 'lib/awetestlib/regression/validations.rb', line 394

def exists?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_exists?(target, desc, refs, how, what, value)
rescue
  rescue_msg_for_validation(desc, refs)
end

#expected_color?(container, element, how, what, style, expected_color, desc = '') ⇒ Boolean

alias validate_enabled enabled?

Returns:

  • (Boolean)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/awetestlib/regression/validations.rb', line 164

def expected_color?(container, element, how, what, style, expected_color, desc = '')
  #TODO: check that style is a color style
  msg          = build_message("Color of #{element} #{how}=>'#{what}' #{style} is #{expected_color}", desc)
  code         = build_webdriver_fetch(element, how, what)
  actual_color = eval("#{code}.style('#{style}')")
  if actual_color == expected_color
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  failed_to_log(unable_to(msg, false, true))
end

#expected_url?(container, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2544

def expected_url?(container, expected, desc = '', refs = '')
  msg = build_message(desc, "Is browser at url #{expected}?", refs)
  if container.url == expected
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg} Found #{container.url}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#fetch_html_err_ref(strg) ⇒ Object



2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2124

def fetch_html_err_ref(strg)
  ref    = ''
  desc   = nil
  tag    = nil
  anchor = nil
  @html_error_references.each_key do |ptrn|
    begin
      mtch = strg.match(ptrn)
    rescue
      debug_to_report(with_caller("'#{$!}'"))
    end
    if mtch
      ref  = @html_error_references[ptrn][:reference]
      desc = @html_error_references[ptrn][:description]
      tag  = mtch[1] if mtch[1]
      case strg
        when /\s*anchor\s*/
          anchor = mtch[2] if mtch[2]
      end
      break
    end
  end
  [ref, desc, tag, anchor]
rescue
  failed_to_log(unable_to)
end

#filter_html_exception?(excp, out, line, validator, location) ⇒ Boolean

Returns:

  • (Boolean)


2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2174

def filter_html_exception?(excp, out, line, validator, location)
  filter    = nil
  action    = nil
  alt_value = nil

  if @html_filters[validator]
    @html_filters[validator].each_key do |key|
      pattern = @html_filters[validator][key][:pattern]
      if excp.match(pattern)
        # msg = build_message('(filtered):', "[id:#{key}]", out, @html_filters[validator][key][:description])

        action = @html_filters[validator][key][:action]

        filter, action, alt_value = html_alt_filter(validator, key, action, line, location)

        case action
          when /ignore|log|warn/i
            filter = key
          when /fail/i
            filter = nil
          else
            debug_to_log(with_caller("Unknown action '#{action}'"))
            filter = nil
        end
        break
      end
    end
  end
  [filter, action, alt_value]
rescue
  failed_to_log(unable_to)
end

#force_boolean(boolean) ⇒ Object



2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2532

def force_boolean(boolean)
  case boolean
    when true, false
      should_be = boolean
    when /yes/i, /true/i
      should_be = true
    else
      should_be = false
  end
  should_be
end

#format_html_excerpt(line, column, pre_length, post_length, tag) ⇒ Object



2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2151

def format_html_excerpt(line, column, pre_length, post_length, tag)
  # debug_to_log(with_caller(tag))
  if line
    column      = 0 if line.size < post_length
    pre_length  = column if column < pre_length
    pre_excerpt = line.slice(column - pre_length, pre_length)
    pre_excerpt.gsub!(/^\s+/, '')
    post_excerpt = line.slice(column, post_length)
    excerpt      = '['
    excerpt << '...' if (column - pre_length) > 1
    excerpt << pre_excerpt if pre_excerpt
    excerpt << '^'
    excerpt << post_excerpt if post_excerpt
    excerpt << '...' if line.size >= (pre_length + post_length)
    excerpt << ']'
    excerpt.ljust(excerpt.size + 1, ' ')
  else
    debug_to_log("Line for #{tag} is nil")
  end
rescue
  failed_to_log(unable_to)
end

#greater_than?(actual, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


797
798
799
800
801
802
803
804
805
806
807
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 797

def greater_than?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' greater than expected '#{expected}'?", refs)
  if actual > expected
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#greater_than_or_equal_to?(actual, expected, desc = '', refs = '') ⇒ Boolean Also known as: greater_than_or_equal?, greater_or_equal?, count_greater_or_equal?

Returns:

  • (Boolean)


809
810
811
812
813
814
815
816
817
818
819
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 809

def greater_than_or_equal_to?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' greater than or equal to expected '#{expected}'?", refs)
  if actual >= expected
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#hashes_match?(exp, act, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1054

def hashes_match?(exp, act, desc = '', refs = '')
  msg = build_message(desc, 'Hashes match?', refs)
  if exp == act
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#html_alt_filter(validator, key, action, line, location) ⇒ Object



2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2207

def html_alt_filter(validator, key, action, line, location)
  filter     = key
  alt_action = action
  mtch_value = nil

  if @html_filters[validator][key][:alt_pattern]

    alt_pattern = @html_filters[validator][key][:alt_pattern]
    mtch        = line.match(alt_pattern)
    if mtch
      mtch_value = mtch[1] if mtch[1]
      alt_action = @html_filters[validator][key][:alt_action]
      case alt_action
        when ''
          filter = nil
        when /fail/i
          filter = nil
        when /ignore/i, /warn/i, /log/i
          filter = key
        else
          debug_to_log(with_caller("Unknown alt_action '#{alt_action}'"))
          alt_action = 'warn'
      end

    else
      alt_action = action
      filter     = nil if action =~ /fail/i
    end

  else
    # TODO This hierarchy is over simple.
    # NOTE: Current assumption is that first found wins
    # NOTE: and only one will be set with an action for a given filter
    [:script, :meta, :head, :body, :fragment, :frame].each do |loc|
      if location[loc] and @html_filters[validator][key][loc]
        alt_action = @html_filters[validator][key][loc]
        filter     = nil if alt_action =~ /fail/i
        break
      end
    end
  end

  [filter, alt_action, mtch_value]
rescue
  failed_to_log(unable_to, 2)
end

#html_line_context(html, container) ⇒ Object



2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2254

def html_line_context(html, container)
  in_script   = false
  in_head     = false
  in_meta     = false
  in_body     = false
  in_frame    = false
  in_fragment = false

  line            = 0
  hash            = {}
  container_class = container.class.to_s
  debug_to_log("container class='#{container_class}'")

  case container_class
    when /frame/i
      in_frame = true
    when /browser/i
      in_frame = false
    else
      in_fragment = true
  end
  html.each do |l|
    target = l.dup.strip

    hash[line] = Hash.new

    hash[line][:frame]    = in_frame
    hash[line][:fragment] = in_fragment

    in_script             = true if target.match(/^\s*<script/)
    in_head               = true if target.match(/^\s*<head>/)
    in_meta               = true if target.match(/^\s*<meta/)
    in_body               = true if target.match(/^\s*<body/)

    hash[line][:script] = in_script
    hash[line][:head]   = in_head
    hash[line][:meta]   = in_meta
    hash[line][:body]   = in_body

    in_script           = false if target.match(/^\s*<script.*\/>$/)
    in_script           = false if target.match(/<\/script>$/)
    in_head             = false if target.match(/<\/head>/)
    in_meta             = false if target.match(/<\/meta.*\/>$/)
    in_script           = false if target.match(/<\/meta>$/)
    in_body             = false if target.match(/<\/body/)

    line += 1
  end

  hash
end

#is_false?(actual, message, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


748
749
750
751
752
753
754
755
756
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 748

def is_false?(actual, message, desc = '', refs = '')
  msg = build_message(desc, "Is '#{message}' false?", refs)
  if actual
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
end

#is_focused?(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ Boolean

Returns:

  • (Boolean)


2582
2583
2584
2585
2586
2587
2588
2589
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2582

def is_focused?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_focused?(target, how, what, value, desc, refs)
rescue
  rescue_msg_for_validation(build_msg(element, how, what), refs)
end

#is_present?(container, element, how, what, value = nil, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


2486
2487
2488
2489
2490
2491
2492
2493
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2486

def is_present?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_is_present?(target, desc, refs, how, what, value)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, value), false, true))
end

#is_true?(actual, message, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


738
739
740
741
742
743
744
745
746
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 738

def is_true?(actual, message, desc = '', refs = '')
  msg = build_message(desc, "Is '#{message}' true?", refs)
  if actual
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
end

#less_than?(actual, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


825
826
827
828
829
830
831
832
833
834
835
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 825

def less_than?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' less than expected '#{expected}'?", refs)
  if actual < expected
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#less_than_or_equal_to?(actual, expected, desc = '', refs = '') ⇒ Boolean Also known as: count_less_or_equal?, less_than_or_equal?, less_or_equal?

Returns:

  • (Boolean)


837
838
839
840
841
842
843
844
845
846
847
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 837

def less_than_or_equal_to?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' less than or equal to expected '#{expected}'?", refs)
  if actual <= expected
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#margins_equal?(container, element, how, what, desc, refs, *pixels) ⇒ Boolean

Returns:

  • (Boolean)


3003
3004
3005
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3003

def margins_equal?(container, element, how, what, desc, refs, *pixels)
  border_sizes_equal?(container, element, how, what, 'margins', desc, refs, *pixels)
end

#not_checked?(browser, how, what, desc = '') ⇒ Boolean

Verify that a checkbox is not checked.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the checkbox is not checked.



359
360
361
362
363
364
365
366
# File 'lib/awetestlib/regression/validations.rb', line 359

def not_checked?(container, how, what, value = nil, desc = '', refs = '')
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_checked?(target, desc, refs, how, what, value)
rescue
  rescue_msg_for_validation(desc, refs)
end

#not_disabled?(container, element, how, what, desc = '', value = nil) ⇒ Boolean Also known as: enabled?, validate_enabled

Returns:

  • (Boolean)


2694
2695
2696
2697
2698
2699
2700
2701
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2694

def not_disabled?(container, element, how, what, desc = '', value = nil, refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_disabled?(target, desc, refs, how, what, value)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, value), false, true))
end

#not_focused?(container, element, how, what, value = nil, desc = '', refs = '', options = {}) ⇒ Boolean Also known as: is_not_focused?

Returns:

  • (Boolean)


2556
2557
2558
2559
2560
2561
2562
2563
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2556

def not_focused?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_focused?(target, how, what, value, desc, refs)
rescue
  rescue_msg_for_validation(build_msg(element, how, what), refs)
end

#not_present?(container, element, how, what, value = nil, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


2509
2510
2511
2512
2513
2514
2515
2516
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2509

def not_present?(container, element, how, what, value = nil, desc = '', refs = '', options = {})
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  element_not_present?(target, desc, refs, how, what, value)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, value), false, true))
end

#not_read_only?(browser, element, how, what, value = nil, desc = '') ⇒ Boolean

Verify that a DOM element is not in read-only state.

Returns:

  • (Boolean)

    Returns true if the element is not in read-only state.



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/awetestlib/regression/validations.rb', line 644

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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the radio button is not set.



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/awetestlib/regression/validations.rb', line 456

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 = build_message("Radio #{how}=>#{what} is not set.", desc)
  if not browser.radio(how, what).set?
    passed_to_log(msg)
    true
  else
    if no_fail
      passed_to_log("#{msg} (Fail suppressed")
    else
      failed_to_log(msg)
    end
  end
rescue
  failed_to_log(unable_to(msg, false, true))
end

#not_visible?(container, element, how, what, desc = '') ⇒ Boolean Also known as: validate_not_visible

Verify that a DOM element is not visible.

Returns:

  • (Boolean)

    Returns true if the element is not visible.



317
318
319
320
321
322
323
# File 'lib/awetestlib/regression/validations.rb', line 317

def not_visible?(container, element, how, what, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  element_not_visible?(target, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what), false, true))
end

#number_does_not_equal?(actual, expected, desc = '', refs = '') ⇒ Boolean Also known as: count_does_not_equal?

Returns:

  • (Boolean)


867
868
869
870
871
872
873
874
875
876
877
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 867

def number_does_not_equal?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' does not equal expected '#{expected}'?", refs)
  if actual == expected
    failed_to_log("#{msg}")
  else
    passed_to_log("#{msg}")
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#number_equals?(actual, expected, desc = '', refs = '') ⇒ Boolean Also known as: count_equals?

Returns:

  • (Boolean)


853
854
855
856
857
858
859
860
861
862
863
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 853

def number_equals?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "Actual '#{actual}' equals expected '#{expected}'?", refs)
  if actual == expected
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end

#padding_equal?(container, element, how, what, desc, refs, *pixels) ⇒ Boolean

Returns:

  • (Boolean)


3011
3012
3013
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3011

def padding_equal?(container, element, how, what, desc, refs, *pixels)
  border_sizes_equal?(container, element, how, what, 'padding', desc, refs, *pixels)
end

#parse_w3c_result(result, exceptions) ⇒ Object



1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1920

def parse_w3c_result(result, exceptions)

  debug_to_log("W3c Markup: #{result.debug_messages}")
  debug_to_log("W3c Markup: error count: #{result.errors.length}")

  instance = 1
  result.errors.each do |excp|
    begin
      debug_to_log("#{instance.to_s.ljust(4, ' ')}: #{excp}", 4)
      if excp =~ /not allowed on element/
        debug_to_log("[#{excp.explanation}]")
      end

      if excp.line
        line                                                     = excp.line.to_i
        column                                                   = excp.col.to_i
        exceptions['w3c_markup']                                 = Hash.new unless exceptions['w3c_markup']
        exceptions['w3c_markup'][:excps]                         = Hash.new unless exceptions['w3c_markup'][:excps]
        exceptions['w3c_markup'][:excps][line]                   = Hash.new unless exceptions['w3c_markup'][:excps][line]
        exceptions['w3c_markup'][:excps][line][column]           = Hash.new unless exceptions['w3c_markup'][:excps][line][column]
        exceptions['w3c_markup'][:excps][line][column][instance] = "line #{line} column #{column} - (#{excp.message_id}) #{excp.message} (w3c_markup)"
      end
      instance += 1
    rescue
      debug_to_log(unable_to("#{instance}"))
    end
  end

rescue
  failed_to_log(unable_to)
end

#pixels_do_not_equal?(container, element, how, what, style, expected, desc = '', refs = '', rounding = 'up') ⇒ Boolean Also known as: pixels_not_equal?

Returns:

  • (Boolean)


2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2737

def pixels_do_not_equal?(container, element, how, what, style, expected, desc = '', refs = '', rounding = 'up')
  code   = build_webdriver_fetch(element, how, what)
  actual = eval("#{code}.style('#{style}')")

  if actual =~ /px$/
    expected = expected.to_s + 'px'
  else
    case rounding
      when 'ceil', 'up'
        actual = actual.to_f.ceil
      when 'down', 'floor'
        actual = actual.to_f.floor
      else
        actual = actual.to_f.round
    end
  end

  msg = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", "pixel size '#{style}",
                      "equals '#{expected}' (with rounding #{rounding})?", refs)

  if actual == expected
    failed_to_log("#{msg} Found '#{actual}'")
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

#pixels_equal?(container, element, how, what, style, expected, desc = '', refs = '', rounding = 'up') ⇒ Boolean

Returns:

  • (Boolean)


2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2769

def pixels_equal?(container, element, how, what, style, expected, desc = '', refs = '', rounding = 'up')
  code   = build_webdriver_fetch(element, how, what)
  actual = eval("#{code}.style('#{style}')")

  if actual =~ /px$/
    expected = expected.to_s + 'px'
  else
    case rounding
      when 'ceil', 'up'
        actual = actual.to_f.ceil
      when 'down', 'floor'
        actual = actual.to_f.floor
      else
        actual = actual.to_f.round
    end
  end

  msg = build_message(desc, "Element #{element.to_s.upcase} :#{how}='#{what}'", "attribute '#{style}",
                      "equals '#{expected}' (with rounding #{rounding})?", refs)

  if actual == expected
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg} Found '#{actual}'")
  end
rescue
  rescue_msg_for_validation(desc, refs)
end

Returns:

  • (Boolean)


837
838
839
840
841
842
843
844
845
846
847
848
# File 'lib/awetestlib/regression/validations.rb', line 837

def popup_is_browser?(popup, desc = '')
  msg = build_message("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)
end

#presence(container, should_be, element, how, what, desc = '') ⇒ Object



2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2462

def presence(container, should_be, element, how, what, value = nil, desc = '', refs = '')
  value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
  code                       = build_webdriver_fetch(element, how, what, options)
  target                     = eval(code)
  if should_be
    element_is_present?(target, desc, refs, how, what, value)
  else
    element_not_present?(target, desc, refs, how, what, value)
  end
rescue
  failed_to_log(unable_to(desc, false, true))
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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • value (String, Regexp)

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the radio button is set.



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/awetestlib/regression/validations.rb', line 487

def radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false)
  msg2 = 'not' if no_fail
  msg = build_message("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.

Returns:

  • (Boolean)

    Returns true if the element is in read-only state.



624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/awetestlib/regression/validations.rb', line 624

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. TODO: Watir-webdriver support

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • value (String, Regexp) (defaults to: '')

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the element is ready.



665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/awetestlib/regression/validations.rb', line 665

def ready?(browser, element, how, what, value = '', desc = '')
  msg2 = "and value=>'#{value}' " if value
  msg = build_message("#{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

#report_html_exceptions(container, exceptions, html_array, html_location, page, filter = true, pre_length = 25, post_length = 50) ⇒ Object



1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1995

def report_html_exceptions(container, exceptions, html_array, html_location, page, filter = true, pre_length = 25, post_length = 50)
  mark_test_level(page)
  message_to_report(build_message('(Filtering disabled)')) unless filter

  exception_count = 0
  error_count     = 0
  log_count       = 0
  warn_count      = 0
  ignored_count   = 0
  unknown_count   = 0
  no_filtering    = 0


  exceptions.keys.sort.each do |validator|
    mark_test_level("Validator: #{validator.titleize}", 5)
    exceptions[validator][:tallies]           = Hash.new
    exceptions[validator][:tallies][:ignore]  = 0
    exceptions[validator][:tallies][:log]     = 0
    exceptions[validator][:tallies][:warn]    = 0
    exceptions[validator][:tallies][:fail]    = 0
    exceptions[validator][:tallies][:unknown] = 0

    # debug_to_log("[#{validator}]")
    exceptions[validator][:excps].keys.sort.each do |line|
      # debug_to_log("[#{line}]")
      next unless line.is_a?(Fixnum)
      exceptions[validator][:excps][line].keys.sort.each do |column|
        # debug_to_log("[#{column}]")
        exceptions[validator][:excps][line][column].keys.sort.each do |instance|

          excp            = exceptions[validator][:excps][line][column][instance]
          exception_count += 1

          mtch       = excp.match(/line\s*(\d+)\s*column\s*(\d+)\s*-\s*(.+)$/)
          arr_line   = (mtch[1].to_i - 1)
          int_column = (mtch[2].to_i - 1)
          desc       = mtch[3]

          tag     = "#{validator}/#{line}/#{column}/#{instance} "
          # debug_to_log(tag, 4)

          excerpt = format_html_excerpt(html_array[arr_line], int_column, pre_length, post_length, tag)
          out     = "#{desc}: line #{line} col #{column} #{excerpt}"

          annotate_html_message(out, html_location[arr_line], line, column)

          if filter

            filter_id, action, alt_value = filter_html_exception?(desc, out, html_array[arr_line], validator, html_location[arr_line])
            alt_value_msg                = alt_value ? "'#{alt_value}'" : nil

            if filter_id
              case action
                when 'log'
                  log_count                             += 1
                  exceptions[validator][:tallies][:log] += 1
                  debug_to_log(build_message("LOGGED [#{filter_id}]: #{out}", alt_value_msg), 5)
                when 'warn'
                  warn_count                             += 1
                  exceptions[validator][:tallies][:warn] += 1
                  message_to_report(build_message("WARN [#{filter_id}]: #{out}", alt_value_msg), 4)
                when 'ignore'
                  ignored_count                            += 1
                  exceptions[validator][:tallies][:ignore] += 1
                  debug_to_log(build_message("IGNORED [#{filter_id}]: #{out}", alt_value_msg), 5)
                else
                  unknown_count                             += 1
                  exceptions[validator][:tallies][:unknown] += 1
                  debug_to_log("unknown action '#{action}' [#{filter_id}]: #{out}", 4)
              end
            else
              out.sub!(/Warning:|\(html5\)/i, 'ERROR:')
              ref, desc, tag, id = fetch_html_err_ref(out)
              ref                = ref.size > 0 ? format_reference(ref) : nil
              if id
                elem = container.element(:id, id)
                debug_to_log(with_caller(build_message(elem.to_subtype, "class=#{elem.class_name}")), 5)
              end
              failed_to_log(build_message(out, desc, ref), 6)
              error_count                            += 1
              exceptions[validator][:tallies][:fail] += 1
            end
          else
            debug_to_report(out)
            no_filtering += 1
          end

        end
      end
    end
  end

  if error_count > 0
    message_to_report(with_caller("#{error_count} HTML validation errors reported"))
  else
    message_to_report(with_caller('No HTML validation errors reported'))
  end
  message_to_report(with_caller("#{warn_count} HTML validation warnings reported")) if warn_count > 0
  debug_to_log(with_caller("total #{exception_count},", "filtering turned off? #{no_filtering},", " errors #{error_count},",
                           " warn #{warn_count},", " log #{log_count},", " ignored #{ignored_count}",
                           " unknown #{unknown_count}"))

  report_results(error_count, with_caller(page))

rescue
  failed_to_log(unable_to)
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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • option (String, Regexp)

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the option is not found.



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/awetestlib/regression/validations.rb', line 539

def select_list_does_not_include?(browser, how, what, which, option, desc = '', refs = '')
  msg         = build_message(desc, "Select list #{how}='#{what}' does not include option with #{which}='#{option}'?", refs)
  select_list = browser.select_list(how, what)
  options     = select_list.options
  case which
    when :text
      found = false
      options.each do |opt|
        if opt.text == option
          found = true
          break
        end
      end
      if found
        failed_to_log(msg)
      else
        passed_to_log(msg)
        true
      end
    else
      if options.include?(option)
        failed_to_log(msg)
      else
        passed_to_log(msg)
        true
      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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • option (String, Regexp)

    A string or a regular expression to be found in the value attribute of the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the option is found.



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/awetestlib/regression/validations.rb', line 516

def select_list_includes?(browser, how, what, which, option, desc = '', refs = '')
  msg         = build_message(desc, "Select list #{how}='#{what}' includes option with #{which}='#{option}'?", refs)
  select_list = browser.select_list(how, what)
  options     = select_list.options
  case which
    when :text
      found = false
      options.each do |opt|
        if opt.text == option
          found = true
          break
        end
      end
      if found
        passed_to_log(msg)
        true
      else
        failed_to_log(msg)
      end
    else
      if options.include?(option)
        passed_to_log(msg)
        true
      else
        failed_to_log(msg)
      end
  end
rescue
  rescue_msg_for_validation(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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the radio button is set.



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/awetestlib/regression/validations.rb', line 432

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 = build_message("Radio #{how}=>#{what} is set.", desc)
  if browser.radio(how, what).set?
    passed_to_log(msg)
    true
  else
    if no_fail
      passed_to_log("#{msg}.  (Fail suppressed)")
    else
      failed_to_log(msg)
    end
  end
rescue
  failed_to_log(unable_to(msg, false, true))
end

#string_contains?(strg, target, desc = '') ⇒ Boolean Also known as: validate_string, validate_string_contains

Returns:

  • (Boolean)


1680
1681
1682
1683
1684
1685
1686
1687
1688
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1680

def string_contains?(strg, target, desc = '', refs = '')
  msg = build_message(desc, "String '#{strg}' contains '#{target}'?", refs)
  if strg.match(target)
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  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

Returns:

  • (Boolean)


1693
1694
1695
1696
1697
1698
1699
1700
1701
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1693

def string_does_not_contain?(strg, target, desc = '', refs = '')
  msg = build_message(desc, "String '#{strg}' does not contain '#{target}'?", refs)
  if strg.match(target)
    failed_to_log(msg)
    true
  else
    passed_to_log(msg)
  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

Parameters:

  • actual (String)

    The actual value as found in the application.

  • expected (String)

    The value expected to be found.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if actual does not match expected.



581
582
583
584
585
586
587
588
589
590
591
# File 'lib/awetestlib/regression/validations.rb', line 581

def string_does_not_equal?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "String '#{actual}' does not equal expected '#{expected}'?", refs)
  if actual == expected
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#string_equals?(actual, expected, desc = '') ⇒ Boolean Also known as: text_equals?, validate_string_equal, validate_string_equals, text_equals

Compare strings for exact match and log results

Parameters:

  • actual (String)

    The actual value as found in the application.

  • expected (String)

    The value expected to be found.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if actual exactly matches expected.



1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1725

def string_equals?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "String '#{actual}' equals expected '#{expected}'?", refs)
  if actual == expected
    passed_to_log(msg)
    true
  else
    failed_to_log(msg)
  end
rescue
  rescue_msg_for_validation(msg)
end

#string_not_equal?Boolean

Returns:

  • (Boolean)


1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1749

def string_does_not_equal?(actual, expected, desc = '', refs = '')
  msg = build_message(desc, "String '#{actual}' does not equal expected '#{expected}'?", refs)
  if actual == expected
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end
rescue
  rescue_msg_for_validation(msg)
end

#style_contains?(container, element, how, what, style, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


2820
2821
2822
2823
2824
2825
2826
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2820

def style_contains?(container, element, how, what, style, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_style_contains?(target, style, expected, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, style), false, true))
end

#style_does_not_contain?(container, element, how, what, style, expected, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


2799
2800
2801
2802
2803
2804
2805
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2799

def style_does_not_contain?(container, element, how, what, style, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_style_does_not_contain?(target, style, expected, desc, refs, how, what)
rescue
  failed_to_log(unable_to(build_msg(element, how, what, style), false, true))
end

#style_does_not_equal?(container, element, how, what, style, expected, desc = '', refs = '') ⇒ Boolean Also known as: color_not_equal?, style_not_equal?, color_does_not_equal?

Returns:

  • (Boolean)


2841
2842
2843
2844
2845
2846
2847
2848
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2841

def style_does_not_equal?(container, element, how, what, style, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")

  element_style_does_not_equal?(target, style, expected, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#style_equals?(container, element, how, what, style, expected, desc = '', refs = '') ⇒ Boolean Also known as: color_equals?

Returns:

  • (Boolean)


2880
2881
2882
2883
2884
2885
2886
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2880

def style_equals?(container, element, how, what, style, expected, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval("#{code}")
  element_style_equals?(target, style, expected, desc, refs, how, what)
rescue
  rescue_msg_for_validation(desc, refs)
end

#text_contains?(container, ptrn, desc = '', refs = '', skip_fail = false, skip_sleep = false) ⇒ Boolean Also known as: validate_text, element_text_equals?

Returns:

  • (Boolean)


1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1772

def text_contains?(container, ptrn, desc = '', refs = '', skip_fail = false, skip_sleep = false)
  name = container.respond_to?(:tag_name) ? container.tag_name.titleize : 'DOM'
  msg  = build_message(desc, "#{name} text contains '#{ptrn}'?", refs)
  if ptrn.is_a?(Regexp)
    target = ptrn
  else
    target = Regexp.new(Regexp.escape(ptrn))
  end
  # debug_to_log(with_caller(__LINE__))
  # if container.respond_to?(:wait)
  #   container.wait
  # elsif container.respond_to?(:wait_until_present)
  #   container.wait_until_present
  # else
  #   sleep(3)
  # end

  # sleep_for(10)
  if container.text.match(target)
    passed_to_log("#{msg}")
    true
  else
    if skip_fail
      debug_to_log("#{name} text does not contain the text: '#{ptrn}'.  #{desc} (Fail suppressed)")
    else
      failed_to_log(msg)
    end
  end
rescue
  rescue_msg_for_validation(msg)
end

#text_does_not_contain?(container, ptrn, desc = '', refs = '') ⇒ Boolean

Returns:

  • (Boolean)


1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1751

def text_does_not_contain?(container, ptrn, desc = '', refs = '')
  name = container.respond_to?(:tag_name) ? container.tag_name.titleize : 'DOM'
  msg  = build_message(desc, "#{name} text does not contain '#{ptrn}'?", refs)

  if ptrn.is_a?(Regexp)
    target = ptrn
  else
    target = Regexp.new(Regexp.escape(ptrn))
  end

  if container.text.match(target)
    failed_to_log(msg)
  else
    passed_to_log(msg)
    true
  end

rescue
  rescue_msg_for_validation(msg)
end

#text_does_not_equal?(container, ptrn, desc = '', refs = '') ⇒ Boolean Also known as: validate_no_text, element_text_does_not_equal?

Returns:

  • (Boolean)


2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2306

def text_does_not_equal?(container, ptrn, desc = '', refs = '')
  name = container.respond_to?(:tag_name) ? container.tag_name.titleize : 'DOM'
  msg  = build_message(desc, "#{name} text contains '#{ptrn}'?", refs)
  if ptrn.is_a?(Regexp)
    target = ptrn
  else
    target = Regexp.new(Regexp.escape(ptrn))
  end
  if container.respond_to?(:wait)
    container.wait
  elsif container.respond_to?(:wait_until_present)
    container.wait_until_present
  else
    sleep(3)
  end
  if container.text.match(target)
    failed_to_log(msg)
  else
    passed_to_log("#{msg}")
    true
  end
rescue
  failed_to_log(unable_to)
end

#text_field_contains?Boolean

Returns:

  • (Boolean)


2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2378

def textfield_contains?(container, how, what, expected, desc = '', refs = '')
  msg      = build_message(desc, "Does text field #{how}='#{what}' contains '#{expected}'?", refs)
  contents = container.text_field(how, what).when_present.value
  if contents =~ /#{expected}/
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg} Contents: '#{contents}'")
  end
rescue
  rescue_msg_for_validation(msg)
end

#text_in_element_equals?(browser, element, how, what, expected, desc = '') ⇒ Boolean

Returns:

  • (Boolean)


916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/awetestlib/regression/validations.rb', line 916

def text_in_element_equals?(browser, element, how, what, expected, desc = '')
  msg  = build_message("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)
end

#textfield_contains?(container, how, what, expected, desc = '') ⇒ Boolean

Verify that a text field (also text area), identified by how and what, contains the string specified in expected.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • expected (String, Regexp)

    A string or regular expression which must be matched in the value of the text field

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the expected is matched in the value of the text field.



728
729
730
731
732
733
734
735
736
737
738
739
# File 'lib/awetestlib/regression/validations.rb', line 728

def textfield_contains?(container, how, what, expected, desc = '', refs = '')
  msg      = build_message(desc, "Does text field #{how}='#{what}' contains '#{expected}'?", refs)
  contents = container.text_field(how, what).when_present.value
  if contents =~ /#{expected}/
    passed_to_log(msg)
    true
  else
    failed_to_log("#{msg} Contents: '#{contents}'")
  end
rescue
  rescue_msg_for_validation(msg)
end

#textfield_does_not_equal?(browser, how, what, expected, desc = '') ⇒ Boolean Also known as: validate_textfield_not_value

Returns:

  • (Boolean)


1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File 'lib/awetestlib/regression/validations.rb', line 1126

def textfield_does_not_equal?(browser, how, what, expected, desc = '')
  msg = build_message("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)
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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the text field is empty.



749
750
751
752
753
754
755
756
757
758
759
760
# File 'lib/awetestlib/regression/validations.rb', line 749

def textfield_empty?(browser, how, what, desc = '', refs = '')
  msg      = build_message(desc, "Text field #{how}='#{what}' is empty?", refs)
  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
  rescue_msg_for_validation(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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • expected (String)

    A string which the value attribute of the text field must equal.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the expected and the value in the text field are identical.



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/awetestlib/regression/validations.rb', line 688

def textfield_equals?(browser, how, what, expected, desc = '', refs = '')
  msg    = build_message(desc, "Expected value to equal '#{expected}' in textfield #{how}='#{what}'?", refs)
  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("#{how}='#{what}'", false, true))
end

#validate_encoding(html, encoding = 'UTF-8') ⇒ Object



1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1849

def validate_encoding(html, encoding = 'UTF-8')
  # ic      = Iconv.new("#{encoding}//IGNORE", encoding)
  encoded = ''

  html_array  = html.split(/\n/)
  line_number = 1

  html_array.each do |line|
    # valid_string = ic.iconv(line + ' ')[0..-2]
    valid_string = line.encode('UTF-16', :invalid => :replace, :replace => '').encode('UTF-8')
    unless line == valid_string
      diffs     = Diff::LCS.diff(valid_string, line)
      diffs_arr = diffs[0]
      debug_to_log("#{diffs_arr}")
      #TODO make message more meaningful by interpretting the nested array.
      debug_to_report("line #{line_number}: '#{diffs.to_s}' removed from '#{line}' to avoid W3C invalid UTF-8 characters error")
    end

    encoded << valid_string << "\n"

    line_number += 1
  end

  [encoded, html_array]

rescue
  failed_to_log(unable_to)
end

#validate_html(container, page, force_browser = false, filter = true) ⇒ Object



1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1808

def validate_html(container, page, force_browser = false, filter = true)
  mark_testlevel(": #{page}")
  # require 'nokogiri-pretty'
  # require 'iconv'
  require 'diff/lcs'

  if force_browser
    html = container.browser.html
  else
    html = container.html
  end

  url = container.browser.url

  html_with_line_feeds = html.gsub("\n", '').gsub('>', ">\n")
  html_with_line_feeds = "<!DOCTYPE html>\n" + html_with_line_feeds unless html_with_line_feeds =~ /^\s*\<\!DOCTYPE/

  pretty_html, html_array = validate_encoding(html_with_line_feeds)

  html_context = html_line_context(html_array, container)

  file_name = page.gsub(' ', '_').gsub('-', '_').gsub('__', '_').gsub(':', '')
  file_name << "_#{get_timestamp('condensed_seconds')}_pretty.html"
  spec = File.join(@myRoot, 'log', file_name)
  file = File.new(spec, 'w')
  file.puts(pretty_html)
  file.close

  exceptions = Hash.new

  validate_with_nokogiri(pretty_html, exceptions)
  validate_with_tidy(url, pretty_html, exceptions)
  # validate_with_w3c_markup_file(spec, exceptions)
  validate_with_w3c_markup(pretty_html, exceptions)

  report_html_exceptions(container, exceptions, html_array, html_context, page, filter)

rescue
  failed_to_log(unable_to, 2)
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.



860
861
862
863
864
865
866
867
868
869
# File 'lib/awetestlib/regression/validations.rb', line 860

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(message)
      true
    end
  end
end

#validate_list_by_name(browser, what, option, desc = '', select_if_present = true) ⇒ Object

Verify that select list contains text



872
873
874
875
876
877
878
879
880
881
# File 'lib/awetestlib/regression/validations.rb', line 872

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(message)
      true
    end
  end
end

#validate_message(browser, message) ⇒ Object

Deprecated.

Use #message_to_log



1295
1296
1297
# File 'lib/awetestlib/regression/validations.rb', line 1295

def validate_message(browser, message)
  message_to_log(message)
end

#validate_select_list(browser, how, what, opt_type, list = nil, desc = '', multiple = false, ignore = ['Select One'], limit = 5) ⇒ Object



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
# File 'lib/awetestlib/regression/validations.rb', line 970

def validate_select_list(browser, how, what, opt_type, list = nil, desc= '',  multiple = false, ignore = ['Select One'], limit = 5)
  mark_testlevel("(#{how}=>#{what})")
  msg  = "Select list #{how}=>#{what}"
  ok          = true
  select_list = browser.select_list(how, what)
  options     = select_list.options
  if list
    if options == list
      passed_to_log(build_message(msg, ": options list equals expected list #{list}"))
    else
      debug_to_report("actual:\n#{nice_array(options, true)}")
      debug_to_report("expected:\n#{nice_array(list, true)}")
      failed_to_log(build_message(
                        msg,
                        ": options list #{nice_array(options, true)}",
                        "does not equal expected list #{nice_array(list, true)}")
                                 )
    end
  end

  #single selections
  cnt = 0
  options.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 options.length > 2
      targets = list.slice(1, 2)
      select_option(select_list, opt_type, options[1])
      select_option(select_list, opt_type, options[2])
      selected = select_list.selected_options
      msg1 = "#{msg}: selected options equals expected #{nice_array(targets)}."
      if selected == targets
        passed_to_log(msg1)
      else
        failed_to_log("#{msg} Found #{nice_array(selected)}")
      end
    else
      debug_to_log("#{msg}: Too few options to test multiple selection (need 2 or more): '#{options}")
    end
  end
rescue
  failed_to_log(unable_to)
end

#validate_select_list_contents(browser, how, what, list, desc = '') ⇒ Object



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
# File 'lib/awetestlib/regression/validations.rb', line 1024

def validate_select_list_contents(browser, how, what, list, desc = '')
  mark_testlevel("#{how}=>#{what}", 2)
  msg  = build_message("Select list #{how}=>#{what} options list equals", nice_array(list), desc)
  select_list = browser.select_list(how, what)
  options     = select_list.options
  if list
    if options == list
      passed_to_log(msg)
      options
    else
      failed_to_log("#{msg}. Found #{nice_array(options)}")
      nil
    end
  end
rescue
  failed_to_log(unable_to)
end

#validate_selected_options(browser, how, what, list, desc = '', which = :text) ⇒ Object Also known as: validate_selections, validate_select_list_selections



3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3077

def validate_selected_options(browser, how, what, list, desc = '', refs = '', which = :text)
  selected_options = browser.select_list(how, what).selected_options.dup
  selected         = extract_selected(selected_options, which)
  sorted_list      = list.dup.sort
  if list.is_a?(Array)
    msg = build_message(desc, "Expected options [#{list.sort}] are selected by #{which} [#{selected}]?", refs)
    if selected == sorted_list
      passed_to_log(msg)
      true
    else
      failed_to_log(msg)
    end
  else
    if selected.length == 1
      msg      = build_message(desc, "Expected option [#{list}] was selected by #{which}?", refs)
      esc_list = Regexp.escape(list)
      if selected[0] =~ /#{esc_list}/
        passed_to_log(msg)
        true
      else
        failed_to_log("#{msg} Found [#{selected}]. #{desc}")
      end
    else
      msg = build_message(desc, "Expected option [#{list}] was found among multiple selections by #{which} [#{selected}]?", refs)
      if selected.include?(list)
        failed_to_log(msg)
      else
        failed_to_log(msg)
      end
    end
  end

rescue
  failed_to_log(unable_to)
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.button(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 = build_message("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
  failed_to_log(unable_to(msg, false, true))
  # 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.button(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 = build_message("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
  failed_to_log(unable_to(msg, false, true))
  # 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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • element (Symbol)

    The kind of element to click. Must be one of the elements recognized by Watir. Some common values are :link, :button, :image, :div, :span.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

  • type (String)

    The name of the style type (sub-attribute) where expected is to be found.

  • expected (String)

    The value in type expected.

Returns:

  • (Boolean)

    True if the style type contains the expected value



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 = build_message("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.button(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(msg, false, true))
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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • how (Symbol)

    The element attribute used to identify the specific element. Valid values depend on the kind of element. Common values: :text, :id, :title, :name, :class, :href (:link only)

  • what (String, Regexp)

    A string or a regular expression to be found in the how attribute that uniquely identifies the element.

  • expected (String)

    A string in dollar formatting

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the expected is matched in the value of the text field.



775
776
777
778
779
780
781
782
783
784
785
786
# File 'lib/awetestlib/regression/validations.rb', line 775

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.

Parameters:

  • browser (Watir::Browser)

    A reference to the browser window or container element to be tested.

  • url (String, Regexp)

    A string or a regular expression to match to the url of the browser..

  • desc (String) (defaults to: '')

    Contains a message or description intended to appear in the log and/or report output

Returns:

  • (Boolean)

    Returns true if the expected is matched in the value of the text field.



793
794
795
796
797
798
799
800
801
802
803
# File 'lib/awetestlib/regression/validations.rb', line 793

def validate_url(browser, url, desc = '')
  msg = build_message("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)
end

#validate_with_nokogiri(html, exceptions) ⇒ Object



1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1878

def validate_with_nokogiri(html, exceptions)
  # mark_test_level
  nokogiri_levels = { '0' => 'None', '1' => 'Warning', '2' => 'Error', '3' => 'Fatal' }

  errors = Nokogiri::HTML(html).errors
  debug_to_log("Nokogiri: error count: #{errors.length}")

  instance = 1
  errors.each do |excp|
    debug_to_log("#{instance.to_s.ljust(4, ' ')}: #{excp}", 4)
    line                                                   = excp.line.to_i
    column                                                 = excp.column.to_i
    exceptions['nokogiri']                                 = Hash.new unless exceptions['nokogiri']
    exceptions['nokogiri'][:excps]                         = Hash.new unless exceptions['nokogiri'][:excps]
    exceptions['nokogiri'][:excps][line]                   = Hash.new unless exceptions['nokogiri'][:excps][line]
    exceptions['nokogiri'][:excps][line][column]           = Hash.new unless exceptions['nokogiri'][:excps][line][column]
    exceptions['nokogiri'][:excps][line][column][instance] = "line #{line} column #{column} - #{nokogiri_levels[excp.level.to_s]}: #{excp.message} (nokogiri)"
    instance                                               += 1
  end

rescue
  failed_to_log(unable_to)
end

#validate_with_tidy(url, html, exceptions) ⇒ Object



1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1952

def validate_with_tidy(url, html, exceptions)
  # mark_test_level
  @html_validator = ::PageValidations::HTMLValidation.new(
      File.join(@myRoot, 'log'),
      [
          #'-access 2'
      ],
      {
          # :ignore_proprietary => true
          #:gnu_emacs          => true
      }
  ) unless @html_validator

  validation = @html_validator.validation(html, url)
  results    = validation.exceptions.split(/\n/)

  debug_to_log("HTML Tidy: error count: #{results.length}")

  instance = 1
  results.each do |excp|
    debug_to_log("#{instance.to_s.ljust(4, ' ')}: #{excp}", 4)
    begin
      mtch = excp.match(/line\s*(\d+)\s*column\s*(\d+)\s*-\s*(.+)$/)
      if mtch
        line   = mtch[1].to_i
        column = mtch[2].to_i
        excp.chomp!
        exceptions['tidy']                                 = Hash.new unless exceptions['tidy']
        exceptions['tidy'][:excps]                         = Hash.new unless exceptions['tidy'][:excps]
        exceptions['tidy'][:excps][line]                   = Hash.new unless exceptions['tidy'][:excps][line]
        exceptions['tidy'][:excps][line][column]           = Hash.new unless exceptions['tidy'][:excps][line][column]
        exceptions['tidy'][:excps][line][column][instance] = excp + ' (tidy)'
      end
      instance += 1
    rescue
      debug_to_log(unable_to("#{instance}"))
    end
  end

rescue
  failed_to_log(unable_to)
end

#validate_with_w3c_markup(html, exceptions) ⇒ Object



1911
1912
1913
1914
1915
1916
1917
1918
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1911

def validate_with_w3c_markup(html, exceptions)
  # mark_test_level
  @w3c_markup_validator = MarkupValidator.new(
      :validator_uri => 'http://wnl-svr017c.wellsfargo.com/w3c-validator/check'
  ) unless @w3c_markup_validator
  result                = @w3c_markup_validator.validate_text(html)
  parse_w3c_result(result, exceptions)
end

#validate_with_w3c_markup_file(html, exceptions) ⇒ Object



1902
1903
1904
1905
1906
1907
1908
1909
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 1902

def validate_with_w3c_markup_file(html, exceptions)
  # mark_test_level
  @w3c_markup_validator = MarkupValidator.new(
      :validator_uri => 'http://wnl-svr017c.wellsfargo.com/w3c-validator/check'
  ) unless @w3c_markup_validator
  result                = @w3c_markup_validator.validate_file(html)
  parse_w3c_result(result, exceptions)
end

#verify_attribute(container, element, how, what, attribute, expected, desc = '', refs = '') ⇒ Object Also known as: validate_attribute_value, verify_attribute_value



3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 3113

def verify_attribute(container, element, how, what, attribute, expected, desc = '', refs = '')
  msg    = element_query_message(element, "#{attribute} equals '#{expected}'?", how, what, nil, desc, refs)
  actual = get_attribute_value(container, element, how, what, attribute, desc)
  if actual == expected
    passed_to_log(msg)
  else
    failed_to_log("#{msg} Found '#{actual}'")
  end
rescue
  failed_to_log(unable_to(msg))
end

#verify_days(list, language = 'English', abbrev = 0, offset = 0, desc = '', refs = '') ⇒ Object



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 777

def verify_days(list, language = 'English', abbrev = 0, offset = 0, desc = '', refs = '')
  #TODO: Handle different starting day: rotate_array(arr, target, index = 0, stop = 0)
  msg       = build_message(desc, "List of xxxx weekdays in #{language} is correct and in order?")
  day_names = get_days(language, abbrev)
  day_names = rotate_array(day_names, offset) if offset > 0
  if abbrev > 0
    msg.gsub!('xxxx', "#{nbr2wd(abbrev)} character")
  else
    msg.gsub!('xxxx', 'fully spelled')
  end
  if list == day_names
    passed_to_log(with_caller(msg, refs))
    true
  else
    failed_to_log(with_caller(msg, refs))
  end
rescue
  failed_to_log(unable_to(msg))
end

#verify_months(list, language = 'English', abbrev = 0, desc = '', refs = '') ⇒ Object



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 758

def verify_months(list, language = 'English', abbrev = 0, desc = '', refs = '')
  msg         = build_message(desc, "List of xxxx months in #{language} is correct and in order?")
  list        = [nil].concat(list)
  month_names = get_months(language, abbrev)
  if abbrev > 0
    msg.gsub!('xxxx', "#{nbr2wd(abbrev)} character")
  else
    msg.gsub!('xxxx', 'fully spelled')
  end
  if list == month_names
    passed_to_log(with_caller(msg, refs))
    true
  else
    failed_to_log(with_caller(msg, refs))
  end
rescue
  failed_to_log(unable_to(msg))
end

#visibility(container, should_be, element, how, what, desc = '') ⇒ Object



2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 2606

def visibility(container, boolean, element, how, what, desc = '', refs = '')
  should_be = force_boolean(boolean)
  if should_be
    visible?(container, element, how, what, desc, refs)
  else
    not_visible?(container, element, how, what, desc, refs)
  end
rescue
  rescue_msg_for_validation(build_msg(element, how, what), refs)
end

#visible?(container, element, how, what, desc = '') ⇒ Boolean Also known as: validate_visible

Verify that a DOM element is visible.

Returns:

  • (Boolean)

    Returns true if the element is visible.



299
300
301
302
303
304
305
# File 'lib/awetestlib/regression/validations.rb', line 299

def visible?(container, element, how, what, desc = '', refs = '')
  code   = build_webdriver_fetch(element, how, what)
  target = eval(code)
  element_visible?(target, desc, refs, how, what)
rescue
  rescue_msg_for_validation(build_msg(element, how, what), refs)
end

#window_does_not_exist?(title) ⇒ Boolean Also known as: window_no_exists

Returns:

  • (Boolean)


821
822
823
824
825
826
827
828
829
# File 'lib/awetestlib/regression/validations.rb', line 821

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

Returns:

  • (Boolean)


809
810
811
812
813
814
815
816
817
# File 'lib/awetestlib/regression/validations.rb', line 809

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

#within_range?(actual, target, min, max = nil) ⇒ Boolean

Returns:

  • (Boolean)


881
882
883
884
885
886
887
888
889
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 881

def within_range?(actual, target, min, max = nil)
  if max
    (min..max).include?(actual)
  else
    ((target - min)..(target + min)).include?(actual)
  end
rescue
  failed_to_log(unable_to, false, true)
end

#within_tolerance?(actual, expected, tolerance, desc = '', refs = '') ⇒ Boolean Also known as: number_within_tolerance?, count_within_tolerance?

Returns:

  • (Boolean)


891
892
893
894
895
896
897
898
899
900
901
902
903
# File 'lib/awetestlib/regression/awetest_dsl.rb', line 891

def within_tolerance?(actual, expected, tolerance, desc = '', refs = '')
  min = expected - tolerance
  max = expected + tolerance
  msg = build_message(desc, "#{actual} is between #{min} and #{max}?", refs)
  if within_range?(actual, expected, tolerance)
    passed_to_log("#{msg}")
    true
  else
    failed_to_log("#{msg}")
  end
rescue
  rescue_msg_for_validation(msg)
end