Module: Watirmark::Controller::Assertions

Included in:
Watirmark::Controller
Defined in:
lib/watirmark/controller/assertions.rb

Instance Method Summary collapse

Instance Method Details

#actual_value(element, expected = nil) ⇒ Object

Returns the user visible value of the element.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/watirmark/controller/assertions.rb', line 22

def actual_value element, expected=nil
  case element
    when Watir::SelectList
      element.getSelectedItems[0]
    when Watir::CheckBox
      element.isSet?
    when Watir::Radio
      if element.valueIsSet?(expected)
        expected
      else
        element.value # not really correct, but the best we can do right now
      end
    when Watir::TextField
      element.value
    else
      if element.value != ''
        element.value
      else
        element.text
      end
  end
end

#assert(result) ⇒ Object



45
46
47
48
49
# File 'lib/watirmark/controller/assertions.rb', line 45

def assert(result)
  if result != true
    raise Watirmark::VerificationException, "Expected true got #{result}"
  end
end

#assert_equal(element, expected) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/watirmark/controller/assertions.rb', line 6

def assert_equal(element, expected)
  return if expected.nil?

  element.extend KeywordElementMethods
  if map = element.radio_map
    expected = map.lookup(expected)
  end

  # Get the actual value
  if element.exists?
    actual = actual_value element, expected
  end
  compare_values(element, expected, actual)
end

#compare_values(element, expected, actual) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/watirmark/controller/assertions.rb', line 51

def compare_values(element, expected, actual)
  @matcher ||= Watirmark::Matcher.new
  if !@matcher.matches(element, expected, actual)
    error = Watirmark::VerificationException.new(@matcher.error_message)
    error.actual = actual
    error.expected = expected
    raise error
  end
end