Class: MiniTest::Assertions

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/ax_elements.rb

Overview

AXElements assertions for MiniTest. Learn more about minitest.

Instance Method Summary collapse

Instance Method Details

#assert_has_child(parent, kind, filters = {}, &block) ⇒ AX::Element

Test that an element has a specific child. For example, test that a table has a row with certain contents. You can pass any filters that you normally would during a search, including a block.

Examples:


assert_has_child table, :row, static_text: { value: 'Mark' }

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
# File 'lib/minitest/ax_elements.rb', line 23

def assert_has_child parent, kind, filters = {}, &block
  msg = message {
    child = ax_search_id kind, filters, block
    "Expected #{parent.inspect} to have #{child} as a child"
  }
  result = ax_check_children parent, kind, filters, block
  refute result.blank?, msg
  result
end

#assert_has_descendent(ancestor, kind, filters = {}, &block) ⇒ AX::Element Also known as: assert_has_descendant

Test that an element has a specifc descendent. For example, test that a window contains a specific label. You can pass any filters that you normally would during a search, including a block.

Examples:


assert_has_descendent window, :static_text, value: /Cake/

Parameters:

Returns:



46
47
48
49
50
51
52
53
54
# File 'lib/minitest/ax_elements.rb', line 46

def assert_has_descendent ancestor, kind, filters = {}, &block
  msg = message {
    descendent = ax_search_id kind, filters, block
    "Expected #{ancestor.inspect} to have #{descendent} as a descendent"
  }
  result = ax_check_descendent ancestor, kind, filters, block
  refute result.blank?, msg
  result
end

#assert_shortly_has(kind, filters = {}) { ... } ⇒ Object

Test that an element will have a child/descendent soon. This method will block until the element is found or a timeout occurs.

This is a minitest front end to using DSL#wait_for, so any parameters you would normally pass to that method will work here. This also means that you must include either a parent key or an ancestor key as one of the filters.

Parameters:

  • (#to_s)
  • (Hash)

Yields:

  • An optional block to be used in the search qualifier



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/minitest/ax_elements.rb', line 69

def assert_shortly_has kind, filters = {}, &block
  # need to know if parent/ancestor now because wait_for eats some keys
  (ancest = filters[:ancestor]) || (parent = filters[:parent])
  msg = message {
    descend = ax_search_id kind, filters, block
    if ancest
      "Expected #{ancest.inspect} to have descendent #{descend} before a timeout occurred"
    else
      "Expected #{parent.inspect} to have child #{descend} before a timeout occurred"
    end
  }
  result = wait_for kind, filters, &block
  refute result.blank?, msg
  result
end

#refute_has_child(parent, kind, filters = {}, &block) ⇒ nil

Test that an element does not have a specific child. For example, test that a row is no longer in a table. You can pass any filters that you normally would during a search, including a block.

Examples:


refute_has_child table, :row, id: 'MyRow'

Parameters:

Returns:

  • (nil)


98
99
100
101
102
103
104
105
# File 'lib/minitest/ax_elements.rb', line 98

def refute_has_child parent, kind, filters = {}, &block
  result = ax_check_children parent, kind, filters, block
  msg    = message {
    "Expected #{parent.inspect} NOT to have #{result} as a child"
  }
  assert result.blank?, msg
  result
end

#refute_has_descendent(ancestor, kind, filters = {}, &block) ⇒ nil, Array() Also known as: refute_has_descendant

Test that an element does not have a specific descendent. For example, test that a window does not contain a spinning progress indicator anymore.

Examples:


refute_has_descendent window, :busy_indicator

Parameters:

Returns:

  • (nil, Array())


120
121
122
123
124
125
126
127
# File 'lib/minitest/ax_elements.rb', line 120

def refute_has_descendent ancestor, kind, filters = {}, &block
  result = ax_check_descendent ancestor, kind, filters, block
  msg    = message {
    "Expected #{ancestor.inspect} NOT to have #{result} as a descendent"
  }
  assert result.blank?, msg
  result
end

#refute_shortly_has(kind, filters = {}) { ... } ⇒ Object

TODO:

Does having this assertion make sense? I've only added it for the time being because OCD demands it.

Test that an element will NOT have a child/descendent soon. This method will block until the element is found or a timeout occurs.

This is a minitest front end to using DSL#wait_for, so any parameters you would normally pass to that method will work here. This also means that you must include either a parent key or an ancestor key as one of the filters.

Parameters:

  • (#to_s)
  • (Hash)

Yields:

  • An optional block to be used in the search qualifier



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/minitest/ax_elements.rb', line 145

def refute_shortly_has kind, filters = {}, &block
  result = wait_for kind, filters, &block
  msg = message {
    if ancest = filters[:ancestor]
      "Expected #{ancest.inspect} NOT to have #{result.inspect} as a descendent"
    else
      parent = filters[:parent]
      "Expected #{parent.inspect} NOT to have #{result.inspect} as a child"
    end
  }
  assert result.blank?, msg
  result
end