2. Real life example
When /^user clicks on Action>>"(.*)" in the book list$/ do |action_name|
book_name_column = column_index "//table[@id='list-table']", 'Name'
@book = first(:xpath,"//table/tbody/tr/td[#{book_name_column}]//a").text
action_column = column_index "//table[@id='list-table']", 'Action'
first(:xpath, "//table/tbody/tr/td[#{action_column}]//a[contains(.,'Action')]").click
first(:xpath, "//table/tbody/tr/td[#{action_column}]//ul/li/a[contains(.,'#{action_name}')]").click
end
3. Problem
When /^user clicks on Action>>"(.*)" in the book list$/ do |action_name|
book_name_column = column_index "//table[@id='list-table']", 'Name'
@book = first(:xpath,"//table/tbody/tr/td[#{book_name_column}]//a").text
action_column = column_index "//table[@id='list-table']", 'Action'
first(:xpath, "//table/tbody/tr/td[#{action_column}]//a[contains(.,'Action')]").click
first(:xpath, "//table/tbody/tr/td[#{action_column}]//ul/li/a[contains(.,'#{action_name}')]").click
end
WHAT vs HOW
4. Be more OO
All problems in computer science can be
solved by another level of indirection
Butler Lampson/David Wheeler
5. PageObject pattern
* HOW becomes the internal implementation details
* WHAT manifests itself in public interface
10. PageObject vs PanelObject
There's an argument here that the name "page object" is
misleading because it makes you think you should have just one
page object per page. Something like "panel object" would be
better - but the term "page object" is what's become accepted.
Another illustration of why naming is one of the TwoHardThings.
Martin Fowler
13. PageObject vs PanelObject
Options:
1) Single object per page
2) Tree of objects (page object -- root)
3) Independent panel object(s) Still over-complicated
Can reveal hierarchy of
complex UI
14. PageObject vs PanelObject
Options:
1) Single object per page
2) Tree of objects (page object -- root)
3) Independent panel object(s)
Simple and flexible
20. Asserts
# Internal approach works well with
# complex asserts
book_list.assert_searchable
# 1. Put a term in the search input
# 2. Hit “Search”
# 3. Check each item contains the term