Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Question: What Is the Best Page Object Framework for Java?

DZone's Guide to

Question: What Is the Best Page Object Framework for Java?

Answer: I don’t know. I don’t use any.

· Java Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

Question: What is the best Page Object framework for Java? And are there any tools to build Page Objects e.g. scan the page and create a class with all the @FindBy annotations on WebElements etc.?

Answer:

I don't know. I have not researched any Page Object frameworks. I don't use any, and I don't recommend any.

I know there are plenty of libraries for other languages

Ruby:

Python:

And there are bound to be more. I don't know.

I prefer to:

  • Write the classes I need by hand.
  • As I need them.
  • Adding methods and WebElements as I use them.
  • Refactoring the classes as they, and my understanding, and our use of them, evolve.

I don’t even recommend using the Page Factory built in to Selenium WebDriver e.g. @FindBy’s etc. because every time I’ve used it, I have eventually moved away from those annotations and the PageFactory.initElements to allow more flexible synchronisation and more flexibility in general.

But note the "every time I've used it." Because…

There was a time when I did want a framework to make it easy.

And there was a time where I not only wanted a tool to scan the page and build a class, but I actually thought about building a tool that would scan the page and build the class, and I think I created some prototype code, but I can't find it now.

But that was when I viewed writing the Page Objects as drudge work. Work that added no value to the automating.

In fact, every class we add has a reason. The classes represent a model of my understanding of the application and how we would go about automating it.

I think being aware of that allows me to build cleaner and simpler code.

Automatically building Page Objects would have led to 'large' Page Objects, which would be unmaintainable ["Ah, but I wouldn't have to maintain them because they would be automatically created."]

They would also be hard to use. Imagine code completion on an automatically created Page Object. There would be no grouping of elements into headers and footers, or identified widgets, there would just be a big list of stuff — and would the automatically generated names read well enough to explain what they were for?

I can understand why such a tool or framework would look attractive, but in the longer term, I think it would hamper, rather than improve, productivity.

It might even prevent you from experimenting.

In the Page Objects and Beyond tutorial and talk, I show code that has many different approaches to abstraction for Page Objects:

  • Element abstractions.
  • Physical abstractions (which are analogous to automatically generated abstractions but with full human control).
  • Logical abstractions.
  • Slow loadable abstractions.
  • Navigation abstractions.

And there are more. You would miss out on Actor/Task type approaches like the screenplay pattern.

I have a general aversion to frameworks.

I don't mind libraries, but anything that controls the way I write the code, I try to minimize my exposure to.

Because I've learned to value flexibility.

I know the code is going to evolve, because I know my understanding will evolve. And my understanding is encoded into the abstractions I write.

I know the application is going to evolve. And I want my code to adapt gracefully as the application changes.

I know I'm going to be refactoring my code, to improve the structure and implementation.

I don't want anything that might get in the way of my doing that.

It could be that there is a perfect framework out there for me, and because I'm not looking for it, I'll never find it.

But I haven't needed it.

P.S. Having said all that, if you find one that works well then let me know.

Moving towards a private or Hybrid cloud infrastructure model? Get started with our OpenStack Deployment Models guide to learn the proper deployment model for your organization.

Topics:
framework ,code ,frameworks ,page objects ,page ,object ,best ,java

Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}