Method: PageObject::Accessors#radio_button

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

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

adds five methods - one to select, another to clear, another to return if a radio button is selected, another method to return a PageObject::Elements::RadioButton object representing the radio button element, and another to check the radio button’s existence.

Examples:

radio_button(:north, :id => "north")
# will generate 'select_north', 'clear_north', 'north_selected?', 
# 'north_element', and 'north?' methods

Parameters:

  • the (String)

    name used for the generated methods

  • identifier (Hash) (defaults to: nil)

    how we find a radio button. 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



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/page-object/accessors.rb', line 359

def radio_button(name, identifier=nil, &block)
  define_method("select_#{name}") do
    return platform.select_radio(identifier.clone) unless block_given?
    self.send("#{name}_element").select
  end
  define_method("clear_#{name}") do
    return platform.clear_radio(identifier.clone) unless block_given?
    self.send("#{name}_element").clear
  end
  define_method("#{name}_selected?") do
    return platform.radio_selected?(identifier.clone) unless block_given?
    self.send("#{name}_element").selected?
  end
  define_method("#{name}_element") do
    return call_block(&block) if block_given?
    platform.radio_button_for(identifier.clone)
  end
  define_method("#{name}?") do
    return call_block(&block).exists? if block_given?
    platform.radio_button_for(identifier.clone).exists?
  end
  alias_method "#{name}_radio_button".to_sym, "#{name}_element".to_sym
end