Method: PageObject::Accessors#checkbox

Defined in:
lib/page-object/accessors.rb

#checkbox(name, identifier = nil, &block) ⇒ Object

adds five methods - one to check, another to uncheck, another to return the state of a checkbox, another to return a PageObject::Elements::CheckBox object representing the checkbox, and a final method to check the checkbox’s existence.

Examples:

checkbox(:active, :name => "is_active")
# will generate 'check_active', 'uncheck_active', 'active_checked?', 
# 'active_element', and 'active?' methods

Parameters:

  • the (String)

    name used for the generated methods

  • identifier (Hash) (defaults to: nil)

    how we find a checkbox. You can use a multiple paramaters by combining of any of the following except xpath. The valid keys are:

    • :class => Watir and Selenium

    • :id => Watir and Selenium

    • :index => Watir and Selenium

    • :name => Watir and Selenium

    • :value => Watir and Selenium

    • :xpath => Watir and Selenium

  • optional

    block to be invoked when element method is called



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/page-object/accessors.rb', line 312

def checkbox(name, identifier=nil, &block)
  define_method("check_#{name}") do
    return platform.check_checkbox(identifier.clone) unless block_given?
    self.send("#{name}_element").check
  end
  define_method("uncheck_#{name}") do
    return platform.uncheck_checkbox(identifier.clone) unless block_given?
    self.send("#{name}_element").uncheck
  end
  define_method("#{name}_checked?") do
    return platform.checkbox_checked?(identifier.clone) unless block_given?
    self.send("#{name}_element").checked?
  end
  define_method("#{name}_element") do
    return call_block(&block) if block_given?
    platform.checkbox_for(identifier.clone)
  end
  define_method("#{name}?") do
    return call_block(&block).exists? if block_given?
    platform.checkbox_for(identifier.clone).exists?
  end
  alias_method "#{name}_checkbox".to_sym, "#{name}_element".to_sym
end