如何在页面 object 小部件中嵌入元素
How to embed an element in a page object widget
我有以下小部件...
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
label :title, :class => "control-label"
def select
self.click
end
def selected?
self.class_name.include? "md-checked"
end
end
PageObject.register_widget :md_radio_button , MdRadioButton, :element
然后我尝试像这样访问标题...
md_radio_buttons(:rdio, :class => "my-radio")
...
rdio_elements.each do |option|
if option.title == alert_group
option.select
end
end
但是当我 option.title
我得到...
undefined method `platform' for #<Watir::HTMLElement:0x162e57d8\>
option.select
工作正常
更新
我试过了...
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
include PageObject
现在 .title
有效,但 .select
无效。
wrong number of arguments (0 for 1)
要使访问器方法在小部件中工作,它们需要访问平台。这可以通过添加 attr_reader
:
来完成
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
attr_reader :platform
label :title, :class => "control-label"
def select
self.click
end
def selected?
self.class_name.include? "md-checked"
end
end
我有以下小部件...
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
label :title, :class => "control-label"
def select
self.click
end
def selected?
self.class_name.include? "md-checked"
end
end
PageObject.register_widget :md_radio_button , MdRadioButton, :element
然后我尝试像这样访问标题...
md_radio_buttons(:rdio, :class => "my-radio")
...
rdio_elements.each do |option|
if option.title == alert_group
option.select
end
end
但是当我 option.title
我得到...
undefined method `platform' for #<Watir::HTMLElement:0x162e57d8\>
option.select
工作正常
更新
我试过了...
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
include PageObject
现在 .title
有效,但 .select
无效。
wrong number of arguments (0 for 1)
要使访问器方法在小部件中工作,它们需要访问平台。这可以通过添加 attr_reader
:
class MdRadioButton < PageObject::Elements::RadioButton
extend PageObject::Accessors
attr_reader :platform
label :title, :class => "control-label"
def select
self.click
end
def selected?
self.class_name.include? "md-checked"
end
end