You cannot use Widget _elements if the base_element_tag is :checkbox
svetlalev opened this issue · 0 comments
svetlalev commented
When you have a custom widget which has a base_element_tag :checkbox the multiple accessor is not working.
Example widget:
class Toggle < PageObject::Elements::CheckBox
def self.accessor_methods(accessor, name)
// some accessor methods
end
end
PageObject.register_widget :toggle, Toggle, :checkbox
When you define a multiple accessor:
class MyPage
include PageObject
toggles :my_toggle, id: 'some_id'
end
When you call it in you test, you get the following error:
NoMethodError: undefined method `checkboxs' for #<Watir::Browser:0x2e3e1221eca4e1fc url="https://some_url" title="xxx">
Did you mean? checkboxes
checkbox
from (eval):1:in `find_watir_elements'
Issue is coming from this line of code: as the base_element_tag
is :checkbox
, the_call we pass to find_watir_elements
is "checkboxs" which is incorrect - it should be "checkboxes".
Possible solution:
define_widget_multiple_accessor
can be changed to something like:
def self.define_widget_multiple_accessor(base_element_tag, widget_class, widget_tag)
send(:define_method, "#{widget_tag}s_for") do |identifier|
call_keyword = base_element_tag == :checkbox ? 'checkboxe' : base_element_tag
find_watir_elements("#{call_keyword}s(identifier)", widget_class, identifier, base_element_tag)
end
end