Class: TestCentricity::CheckBox

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

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary collapse

Attributes inherited from UIElement

#alt_locator, #base_object, #context, #locator, #locator_type, #name, #original_style, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #content_editable?, #count, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #height, #hidden?, #highlight, #hover, #hover_at, #inspect, #obscured?, #right_click, #role, #scroll_to, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x, #y

Constructor Details

#initialize(name, parent, locator, context) ⇒ CheckBox

Returns a new instance of CheckBox.



6
7
8
9
10
11
12
13
14
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 6

def initialize(name, parent, locator, context)
  super
  @type = :checkbox
  check_spec = {
    proxy: nil,
    label: nil
  }
  define_custom_elements(check_spec)
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



4
5
6
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 4

def label
  @label
end

#proxyObject

Returns the value of attribute proxy.



3
4
5
# File 'lib/testcentricity_web/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


131
132
133
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 131

def check
  set_checkbox_state(true)
end

#checked?Boolean

Is checkbox checked?

Examples:

remember_me_checkbox.checked?

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 46

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

#define_custom_elements(element_spec) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 16

def define_custom_elements(element_spec)
  element_spec.each do |element, value|
    case element
    when :proxy
      @proxy = value
    when :label
      @label = value
    else
      raise "#{element} is not a recognized checkbox element"
    end
  end
end

#disabled?Boolean

Is checkbox disabled (not enabled)?

Examples:

remember_me_checkbox.disabled?

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 79

def disabled?
  visibility = @proxy.nil? ? true : :all
  obj, type = find_element(visibility)
  object_not_found_exception(obj, type)
  obj.disabled?
end

#exists?Boolean

Does checkbox object exists?

Examples:

remember_me_checkbox.exists?

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 35

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

#get_valueBoolean Also known as: get_caption, caption, value

Return checkbox caption

Examples:

remember_me_checkbox.get_value

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 92

def get_value
  if @label.nil?
    @proxy.nil? ? super : page.find(:css, @proxy).text
  else
    page.find(:css, @label).text
  end
end

#indeterminate?Boolean

Is checkbox state indeterminate?

Examples:

remember_me_checkbox.indeterminate?

Returns:

  • (Boolean)


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

def indeterminate?
  state = get_attribute('indeterminate')
  state.boolean? ? state : state == 'true'
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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 110

def set_checkbox_state(state)
  obj, = find_element(:all)
  object_not_found_exception(obj, 'Checkbox')
  invalid_object_type_exception(obj, 'checkbox')
  if @proxy.nil?
    if obj.native.attribute('ot') == 'JCheckBox'
      expected = state.to_bool
      obj.click unless expected == obj.checked?
    else
      obj.set(state)
    end
  else
    page.find(:css, @proxy).click unless state == obj.checked?
  end
end

#uncheckObject

Uncheck a checkbox object.

Examples:

remember_me_checkbox.uncheck


140
141
142
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 140

def uncheck
  set_checkbox_state(state = false)
end

#verify_check_state(state, enqueue = false) ⇒ Object



144
145
146
147
148
149
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 144

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

#visible?Boolean

Is checkbox visible?

Examples:

remember_me_checkbox.visible?

Returns:

  • (Boolean)


69
70
71
# File 'lib/testcentricity_web/web_elements/checkbox.rb', line 69

def visible?
  @proxy.nil? ? super : page.find(:css, @proxy).visible?
end