I have 2 different ways of working with the driver in the page object model:

  1. Creating the driver in all the pages and passing it from one class to another. You have an example here.

  2. Extending the classes to a Base class where the driver is created. You have an example here

Can you tell me the pro/cons between this two options?

  • I really like this question. I will admit it was difficult for me to follow your code in the repos. If you could post a small snippet from each giving an example of exactly what you are referring to it will likely result in better answers.
    – Paul Muir
    Oct 31, 2016 at 16:08
  • 2
    If you use Spring, I recommend injecting the driver (or an object containing the driver) into every test class.
    – user246
    Oct 31, 2016 at 19:11
  • 1
    Links are broken
    – FDM
    Nov 7, 2016 at 19:36

2 Answers 2


I would personally suggest you while working with POM first design your TestBaseSetup class. In this initialize your drivers and the same driver you can use it in your page object class by passing 'constructor' of the base class to your all object classes.

This will create Page Object classes. For each page, we will create a separate class with a constructor. We identify the locators and keep all together on just below the class. This will help us to reuse the locators for multiple methods and the main important is, we can easily find the locator and change if required.

We need to identify and a list of all the possible functionalities on this page and we should write methods in such a way they are re-used. When ever there is a method to click on a button or link, we should return driver object of that page.

For more details how to design POM, you can check here.


I like using a base class because it means there's less code duplication. Whenever I think of something that I have to repeat each time for a class, it's a good time to look and see if there's a better way to refactor that duplication and save yourself some work. Adding a base class is one way to do this.

Also, your links aren't working for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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