Class: TestCentricity::CheckBox

Inherits:
UIElement show all
Defined in:
lib/testcentricity_web/elements/checkbox.rb

Instance Attribute Summary collapse

Attributes inherited from UIElement

#alt_locator, #context, #locator, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#clear_alt_locator, #click, #click_at, #disabled?, #double_click, #drag_by, #enabled?, #get_attribute, #get_locator, #get_native_attribute, #get_object_type, #get_siebel_object_type, #get_value, #hidden?, #hover, #invoke_siebel_dialog, #send_keys, #set, #set_alt_locator, #verify_value, #visible?, #wait_until_exists, #wait_until_gone, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible

Constructor Details

#initialize(parent, locator, context, proxy = nil) ⇒ CheckBox

Returns a new instance of CheckBox.



5
6
7
8
9
10
11
12
# File 'lib/testcentricity_web/elements/checkbox.rb', line 5

def initialize(parent, locator, context, proxy = nil)
  @parent      = parent
  @locator     = locator
  @context     = context
  @proxy       = proxy
  @type        = :checkbox
  @alt_locator = nil
end

Instance Attribute Details

#proxyObject

Returns the value of attribute proxy.



3
4
5
# File 'lib/testcentricity_web/elements/checkbox.rb', line 3

def proxy
  @proxy
end

Instance Method Details

#checkObject

Set the check state of a checkbox object.

Examples:

remember_me_checkbox.check


59
60
61
# File 'lib/testcentricity_web/elements/checkbox.rb', line 59

def check
  set_checkbox_state(true)
end

#checked?Boolean

Is checkbox checked?

Examples:

remember_me_checkbox.checked?

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/testcentricity_web/elements/checkbox.rb', line 31

def checked?
  obj, _ = find_element(:all)
  object_not_found_exception(obj, 'Checkbox')
  obj.checked?
end

#exists?Boolean

Does checkbox object exists?

Examples:

remember_me_checkbox.exists?

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/testcentricity_web/elements/checkbox.rb', line 20

def exists?
  obj, _ = find_object(:all)
  obj != nil
end

#set_checkbox_state(state) ⇒ Object

Set the check state of a checkbox object.

Examples:

remember_me_checkbox.set_checkbox_state(true)

Parameters:

  • state (Boolean)

    true = checked / false = unchecked



43
44
45
46
47
48
49
50
51
52
# File 'lib/testcentricity_web/elements/checkbox.rb', line 43

def set_checkbox_state(state)
  obj, _ = find_element(:all)
  object_not_found_exception(obj, 'Checkbox')
  invalid_object_type_exception(obj, 'checkbox')
  if @proxy.nil?
    obj.set(state)
  else
    @proxy.click unless state == obj.checked?
  end
end

#set_siebel_checkbox_state(state) ⇒ Object

Set the check state of a Siebel OUI JCheckBox object.

Examples:

remember_me_checkbox.set_siebel_checkbox_state(true)

Parameters:

  • state (Boolean)

    true = checked / false = unchecked



85
86
87
88
89
90
91
# File 'lib/testcentricity_web/elements/checkbox.rb', line 85

def set_siebel_checkbox_state(state)
  obj, _ = find_element
  object_not_found_exception(obj, 'Siebel checkbox')
  raise "#{locator} is not a Siebel CheckBox object" unless get_siebel_object_type == 'JCheckBox'
  expected = state.to_bool
  obj.click unless expected == obj.checked?
end

#uncheckObject

Uncheck a checkbox object.

Examples:

remember_me_checkbox.uncheck


68
69
70
# File 'lib/testcentricity_web/elements/checkbox.rb', line 68

def uncheck
  set_checkbox_state(false)
end

#verify_check_state(state, enqueue = false) ⇒ Object



72
73
74
75
76
77
# File 'lib/testcentricity_web/elements/checkbox.rb', line 72

def verify_check_state(state, enqueue = false)
  actual = checked?
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(state, actual, "Expected #{@locator}") :
      assert_equal(state, actual, "Expected #{@locator} to be #{state} but found #{actual} instead")
end