I'm using the "PageObject" gem and Ruby and created a widget using the "page-object wiki" as a reference.
I cannot find plural elements, meaning I can't find an array of elements.
If the tag for my widget is some-widget, this works:
some_widget_element(id: 'some-id')
But this does NOT work:
some_widget_elements(id: 'some-id')
I am trying to find multiple elements by id, which is how the page is structured.
I get the error:
NoMethodError: undefined method 'new' for nil:NilClass
Is there anything I need to do/add to my Widget class?
Registering a widget will define both:
As an example, let's assume the following HTML:
As well, that we have registered the widget:
Nested Element
The created nested element method is in the form "{widget_tag}_elements".
Page-Level Accessor
By default, the page-level accessor for returning an Array of all matching widgets is based on the widget's class name. This differs from the singular accessor method, which you define when registering the widget. Specifically, the method name is defined by the following expression:
In our example, the
SomeWidgetClassclass would create asome_widget_classsmethod:You can override the accessor name by defining the
plural_formfor your widget. The following renames the method toplural_widgets:The actual usage of the page does not change - ie is still
page.my_widgets_elements.