Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:44:13+00:00 2026-06-13T18:44:13+00:00

I’ve been working on a team that’s been developing a Selenium WebDriver infrastructure for

  • 0

I’ve been working on a team that’s been developing a Selenium WebDriver infrastructure for a few months now, and something about the way we access the driver object from test cases and page objects is bugging me.

Our test cases create a new WebDriver instance and open the browser. This new instance is stored in the test case class.

Then, the test case instantiates a page object. Following along with Selenium’s Page Object Pattern, these page objects take the WebDriver as a parameter in their constructor (though I notice in our version it isn’t final). The various page object methods use the driver that was set in the page object’s constructor to do what they do. If a page object method navigates to a new page object, then the WebDriver is passed on to it. Just like in Selenium’s example:

public class LoginPage {
    private final WebDriver driver;

    public LoginPage(WebDriver driver) {
        this.driver = driver;

        // Check that we're on the right page.
        if (!"Login".equals(driver.getTitle())) {
            // Alternatively, we could navigate to the login page, perhaps logging out first
            throw new IllegalStateException("This is not the login page");
        }
    }

    // Conceptually, the login page offers the user the service of being able to "log into"
    // the application using a user name and password. 
    public HomePage loginAs(String username, String password) {
        // This is the only place in the test code that "knows" how to enter these details
        driver.findElement(By.id("username")).sendKeys(username);
        driver.findElement(By.id("passwd")).sendKeys(password);
        driver.findElement(By.id("login")).submit();

        // Return a new page object representing the destination. Should the login page ever
        // go somewhere else (for example, a legal disclaimer) then changing the method signature
        // for this method will mean that all tests that rely on this behaviour won't compile.
        return new HomePage(driver);
    }
}

This makes it seem as though the WebDriver instance is unique and important, like a torch that must be passed from page object to page object. The style of the code led me to think that I always had to make sure I was using the same instance of the driver that was used in the last operation.

But this “passing of the torch” becomes complicated or impossible with situations where there are multiple page objects on a page, and page object methods don’t return the page object that you are planning on working with next. How can you operate on the same WebDriver instance when you’ve got two page objects on the screen, and you need to alternate between them, without switching to a new page or creating new page objects?

All this confusion leads me to believe that no passing of the torch is actually necessary, or maybe even happening (are all these page objects storing references to the same WebDriver instance?), but then I don’t know why that pattern was suggested in the description given by Selenium.

So, do I need to worry about “passing the torch?” Or will any page object operate fine once instantiated with its WebDriver, even if other page objects perform operations with their own versions of the same WebDriver in the interim?

Would it be easier/better to just make the WebDriver a singleton, accessible to all, since we won’t be using more than one WebDriver per JVM at any given time? Then we wouldn’t need to pass the WebDriver around in constructors at all. Thanks in advance for any input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:44:14+00:00Added an answer on June 13, 2026 at 6:44 pm

    It is better to mark the webdriver as a singleton for the entire framework. I had been currently using this pattern and it works fine.
    Note: Care should be taken when dealing with parallel execution.

    @CodeEnthusiastic
    For example take a class GeneralLibrary, in that create a WebDriver.

    Extend the classes in Page Object Model with GeneralLibrary as super class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.