Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You cannot use Widget _elements if the base_element_tag is :checkbox #506

Open
svetlalev opened this issue Dec 7, 2022 · 0 comments
Open

Comments

@svetlalev
Copy link

svetlalev commented Dec 7, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant