Simon, I've just seen the video of your presentation in GTAC, and I
found your idea of PageObjects very interesting.
Do you have any pointers for additional information?
thanks,
Jn
There's two ways of answering that question: either by recapping and
expanding on the information presented at the conference, or providing
some background that's relevant. I'll try and do both :)
So, Page Objects as they were presented:
* They're "Janus"-like.
* Facing toward the developer, they offer the services that the page
they represent offer (such as "login" or "get the balance of account
X")
* Facing "inwards", away from the user, they have a deep knowledge
of the internal structure (that is, HTML) of the page.
* They should return other Page Objects from the various methods on them.
There are a number of things to bear in mind that fall out of this:
* Page Objects expose "intent" --- the "what", not the "how". If you
ever find yourself exposing information about the underlying HTML (for
example, "get the content of the cell at row 5, column 7 from table
Y") then there's a strong chance that you're not quite using them
right.
* Because the methods on a Page Object return other Page Objects, you
can model the navigation through your app. When that navigation
changes, change the signature of the method and your tests won't even
compile until you've fixed them. That's the fastest feedback you can
get in Java!
* Because we're using a strongly typed language, you may well end up
with methods such as "logon" and "logonExpectingAnError" which return
different Page Objects. That's fine.
* Because the Page Object is the only thing that understands the
structure of the HTML, when you change how a page is laid out, or some
functionality is handled, you only need to change the Page Object, not
the tests that use it.
* The Page Object should not make assertions: that's the
responsibility of the test.
The important thing to remember is that you should be doing what's
most appropriate for you. For example, I quite like to make an
assertion on the page title in a Page Object's constructor, despite
that last point since that allows me to fail a test quickly.
And now for some more background:
I did a series of blog posts a while ago, which included something on
Page Objects, and some other patterns that I like to use:
http://www.pubbitch.org/blog/2006/01/01/take_it_from_the_top_part_two
http://www.pubbitch.org/blog/2006/01/02/take_it_from_the_top_part_three
http://www.pubbitch.org/blog/2006/01/03/take_it_from_the_top_part_four
The idea for Page Objects came out of thinking about the roles and
responsibilities of various objects being modelled in test code. I'm
not the only one to have done that thinking and reached the same sort
of basic model as other people. The version that I talked about at
GTAC has been refined over several projects, and has had input from
lots of people.
If you're interested in thinking about the objects in your system,
then I'd recommend two books "Object Thinking" and "Domain Driven
Design"
That's a bit of a long and rambling answer, but I hope it helped. :)
Regards,
Simon
Object Thinking: http://www.amazon.com/exec/obidos/tg/detail/-/0735619654
Domain Driven Design: http://www.amazon.com/exec/obidos/tg/detail/-/0321125215