cheezy/page-object — pull request #145 by wjpowell (2012-12-18 04:06:42+00:00)
Title: Adding extensibility to simplify testing of gwt/gxt applications

I have simplified the creation of widgets for the PageObject gem by adding a Widgets module, and a register_widgets method to PageObject. This module allows for the easy creation of test widgets, 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, I extend the PageObject::Element::Table class:

```ruby
class GxtTable < PageObject::Elements::Table

@protected
def child_xpath
".//descendant::tr"
end
end
```

I 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.

```ruby
Widgets.register_widget :gxt_table, GxtTable, :div
```

The GxtTable then behaves as if it were an html element for the purpose of page-object definitions.

```ruby
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
```