-
Notifications
You must be signed in to change notification settings - Fork 220
Widgets (registering custom elements with PageObject)
PageObject supports the easy creation of test widgets. These widgets are primarily used for interacting with Gwt or Gxt web applications.
For example, a Gxt table consists of multiple div elements, and each row is itself a table element containing a single row. To interact with the Gxt table, extend the PageObject::Element::Table class:
class GxtTable < PageObject::Elements::Table
protected
def child_xpath
".//descendant::tr"
end
end
Then register the class with the PageObject gem. The register_widget method accepts a tag which will be used as the accessor, the class which will be added to the Elements module, and a html element tag which will be used as the top-level html element of the widget, or the html element used in the watir or selenium search.
PageObject.register_widget :gxt_table, GxtTable, :div
The GxtTable then behaves as if it were an html element for the purpose of page-object definitions.
class WidgetTestPageObject
include PageObject
gxt_table(:a_table, :id => "top_div_id")
gxt_table :gxt_block_table do |element|
"block_gxt_table"
end
div(:outer_div)
gxt_table(:a_nested_gxt_table) {|page| page.outer_div_element.gxt_table_element}
end
PageObject does not provide a default method for elements defined in this way. Instead, it adds the "[tag]_element" method to return an object, and a "[tag]?" method to check for existence. In the example above "a_table_element" and "a_table?" would both be valid methods for WidgetTestPageObject, but "a_table" will not be found