[QA] Page Object design pattern: where to put element identifiers/selectors

Chris McMahon cmcmahon at wikimedia.org
Thu Mar 20 22:54:49 UTC 2014


The Page Object design pattern divides browser tests into three areas:  the
controller, where the test is created (this is a description of the test):
 the steps of the test, which are actions taken by the test (the steps are
verbs, actions, navigation from one place to another and checking on
status; and the page definitions, which are the nouns against which the
steps/actions/verbs are working.

In our implementation of the Page Object pattern:

* the Cucumber feature files are the story of the tests
* the steps.rb files are the verbs and actions
* the page.rb files are the nouns and the pages

If you know anything about Design Patterns, you may know that they are
discovered, not invented. Among people who do browser testing, the Page
Object design pattern is generally accepted to be the best known solution
for creating  browser tests that are robust, readable, maintainable, and
that will scale to large numbers of tests.

In practice, that boils down to some rules that we need to follow, and one
of those rules is:  *no element identifiers in steps files*.  Page elements
like div and span that have identifiers of e.g. class: and css: need to be
managed in the page.rb files and *only* in the page.rb files.

Do not put page element identifiers into the steps of the test.  This makes
the tests difficult to read, difficult to scale, and very difficult to
maintain.

Adhere to the Page Object design pattern:  keep your page element
identifiers in the /support/pages/*page.rb files ONLY, and NOT in the
/step_definitions/*steps.rb files.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wikimedia.org/pipermail/qa/attachments/20140320/987f3313/attachment.html>


More information about the QA mailing list