div(:reward_history, :class => 'reward-history-header')
'reward_history', 'reward_history_element', and 'reward_history?'
def is_reward_history_present?
return reward_history_element.present?
end
module PageObject
module Accessors
def standard_methods(name, identifier, method, &block)
define_method("#{name}_element") do
return call_block(&block) if block_given?
platform.send(method, identifier.clone)
end
define_method("#{name}?") do
return call_block(&block).present? if block_given?
platform.send(method, identifier.clone).present?
end
end
end
end
expect(on(MyAccountPage).reward_history?).to be_falsey
expect(on(MyAccountPage).reward_history?).to eq false
div(:expand_perks_section_icon, :css => '.icon-plus-wrapper')
def expand_perks_section expand_perks_section_icon_element.when_present.click end
def a
'hi'
end
def a
'bye'
end
puts a
#=> "bye"
# A class to represent your control (ie div that acts like a button)
class DivButton < PageObject::Elements::Div
def self.accessor_methods(accessor, name)
# Adds method to perform click
accessor.send(:define_method, "#{name}") do
self.send("#{name}_element").click
end
end
end
PageObject.register_widget :div_button, DivButton, :div
class MyPage
include PageObject
# Use div_button instead of div to use your widget
div_button(:expand_perks_section_icon, :css => '.icon-plus-wrapper')
end
page = MyPage.new(browser)
page.expand_perks_section_icon #=> triggers click on div
page.expand_perks_section_icon? #=> has standard method to check element existence (or presence with the monkey patch)