1

I read this article about flaws in the Page Object Model/POM, authored by a lady at ThoughtWorks - https://blog.getgauge.io/are-page-objects-anti-pattern-21b6e337880f

She says that POM leads to excess code and maintainability issues. For example, she goes against the general recommendation that Page Objects/POs should return other POs - See the content under the heading "Method chaining".

Are these arguments sound ? Are there any genuine flaws in the POM ?

  • What is your own personal experience? – Vishal Aggarwal Apr 18 at 1:11
  • I strongly think there is no "One size fits all" solutions . – Vishal Aggarwal Apr 18 at 1:15
5

I think if you stick to simple PageObjects as described by Martin Fowler it is fine. It should be a simple abstraction to keep your test-code DRY, reusable and increase readability by using page-methods that describe behaviour of the page/view.

The linked article is mainly about issues with Page Factories and thinking PageObjects have to return another Page (they don't, but sometimes it is very handy!). Personally I have never seen a use for PageFactories, they do magic stuff I don't need, are verbose, etc.. Nor do I see the need for an extra Step layer that the suggested Guage adds. For me that is similar overhead and introduces other pains.

Just keep it simple, and only add complexity when you need it.

  • Could you please mention which overheads the step layer adds and what are your concerns about them ? Thanks. – MasterJoe2 May 8 at 4:23
  • 1
    With BDD frameworks you have to map human-readable steps to test-code. If you do not use the human-readable steps as a communication tool you just got an extra tool to understand and install and extra layering in your code which adds complexity. In my experience programmers maintaining and extending test suites in BDD frameworks do not see the added value, just more typing. See: docs.gauge.org/latest/… – Niels van Reijmersdal May 8 at 7:18
  • Thanks. That example makes is crystal clear. I'd prefer to start writing code right away instead of creating all those steps, tables etc in fixed formats. I am sure that I'd need to deviate from the formats for some test and then, I'd have to use a workaround or just use plain code instead of the framework. – MasterJoe2 May 8 at 18:42
3

I will not go into the details of what the problems are regarding Page Objects, there are lot's of articles on the net by people who put in more thought than me. From my experience though I would go with https://johnfergusonsmart.com/beyond-page-objects-liberate-chains-ui-think/ in saying: page objects are fine but another level of abstraction is helpful like the Screenplay Pattern

In short: yes, the arguments are sound, there are flaws. Page Objects still have their reason to exists for learning and as stepping stone to better models.

3

The conclusion that

She says that POM leads to excess code and maintainability issues.

is wrong.

Page Objects is a a concept that can be implemented in many ways.
They solve two simple problems:

  • They reduce duplication
    DRY is usually good

  • They name stuff
    One of the two hard problems in computer science

They reduce maintainability issues - the exact opposite of one of the points you list

I think a simple example will show both:

I will use pseudo-code

Without page objects

find ('div#main_content input#name').click   #for focus
fill_in('div#main_content input#name'), with: 'Bob'
expect(find('div#main_content input#name')).to have_Value 'Bob'

With Page objects

name = div#main_content input#name # probably done in a setup file

find(name).click
fill_in(name), with: 'Bob'
expect(find(name)).to have_value 'Bob'

The second seems much more readable to me.
Also, although both would need to be changed if the locator changed, in the second case this change is only in one place, whereas in the first case the locator in 3 different places would need to be updated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.