如何在页面对象窗口小部件中嵌入元素

时间:2016-05-26 20:39:50

标签: pageobjects page-object-gem

我有以下小部件......

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时,我得到了......

  

未定义的方法`平台&#39;对于#&lt; Watir :: HTMLElement:0x162e57d8 \&gt;

option.select工作正常

更新

我试过了......

class MdRadioButton < PageObject::Elements::RadioButton
  extend PageObject::Accessors
  include PageObject

现在.title有效但.select没有。

  

错误的参数数量(0表示1)

1 个答案:

答案 0 :(得分:3)

要使访问者方法在窗口小部件中工作,他们需要访问该平台。这可以通过添加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