During the process of developing a web application, the structure of web pages often changes. If you have several Selenium tests that test different functionalities of one page, you don’t want to change all your tests if the page changes only its layout.
Let say you have twelve tests which access the page. Now you need to change the page to display an additional table row. Your selenium test would probably fail, because the expected data is now at a different place on the page.
The solution: Use abstractions!
Your tests should not access the page structure itself but use abstractions of the page. This means you would only need to adapt the abstraction of the page and the twelve tests wouldn’t need any modification.
Page objects should be the only thing that have a deep knowledge of the structure of the HTML of a page. Think of the methods on a Page Object as offering the “services” that a page offers rather than exposing the HTML strucure of the web page.
From the Page objects page:
As an example, think of the inbox of any web-based email system. Amongst the services that it offers are typically the ability to compose a new email, to choose to read a single email, and to list the subject lines of the emails in the inbox. How these are implemented shouldn’t matter to the test.
“People who can code in the world of technology companies are a dime a dozen and get no respect. People who can code in biology, medicine, government, sociology, physics, history, and mathematics are respected and can do amazing things to advance those disciplines.”
An excellent Talk by Robert Martin called “What Killed Smalltalk Could Kill Ruby, Too” that shows why test driven development (TDD) as a concept is so important, not only for Ruby projects but for every software project.