Quick revision
The short answer
In recent Selenium 4 releases, new ChromeDriver(options) is enough: Selenium Manager, bundled since 4.6, finds or downloads a chromedriver that matches the installed Chrome, and in later 4.x releases can also download a Chrome for Testing browser when none is installed (check your version). For CI we add --headless=new and a fixed window size such as --window-size=1920,1080 to ChromeOptions, pin the browser version with setBrowserVersion or a fixed container image, and always call driver.quit() after each test so browser processes do not leak.
What to remember
In this answer, we saw that Selenium needs a chromedriver that matches Chrome, and that in recent Selenium 4 releases Selenium Manager resolves and caches it automatically, and can download Chrome for Testing when needed, so manual driver paths and WebDriverManager are mostly unnecessary. We pinned the browser version on CI with setBrowserVersion or a fixed image, ran headless with --headless=new and a fixed window size, and quit the driver after every test so no browser processes leak.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In recent Selenium 4 releases, new ChromeDriver(options) is enough: Selenium Manager, bundled since 4.6, finds or downloads a chromedriver that matches the installed Chrome, and in later 4.x releases can also download a Chrome for Testing browser when none is installed (check your version). For CI we add --headless=new and a fixed window size such as --window-size=1920,1080 to ChromeOptions, pin the browser version with setBrowserVersion or a fixed container image, and always call driver.quit() after each test so browser processes do not leak.
Why this question is asked
Starting a browser used to be the most fragile line in a Selenium test. Every Chrome update could break the build with a version mismatch, and every project carried instructions for downloading the right driver binary. Selenium 4 changed that, and interviewers ask this question to check whether our setup knowledge is current, and whether we understand what happens behind one constructor call. In this answer, we will recap the pieces that must fit together, see what Selenium Manager does when we create a driver, look at how versions are matched and pinned, configure headless runs for CI, and finish with closing the browser correctly, including the difference between quit() and close().
1A Quick Recap: Browser, Driver and Selenium
Three pieces work together. The browser is Chrome itself. The driver, chromedriver, is a separate small program that speaks the W3C WebDriver protocol and controls the browser; each chromedriver release supports one Chrome major version. Selenium is the Java library our test calls; it starts chromedriver and sends it HTTP commands such as navigate, find element and click. If chromedriver and Chrome do not match, the session fails to start with an error that this version of chromedriver only supports a particular Chrome version.
In older setups, we downloaded chromedriver by hand and pointed Selenium at it with System.setProperty("webdriver.chrome.driver", "/opt/drivers/chromedriver"), or used the third-party WebDriverManager library to download it at runtime. Both are now mostly unnecessary.
2What Selenium Manager Does
Selenium Manager is a small tool that ships inside the Selenium library since version 4.6. When we create a driver without specifying a driver path, Selenium calls it automatically. It detects the installed Chrome and its version, checks whether a matching chromedriver is on the PATH or in its cache, downloads one if needed, and returns the path to Selenium. Later 4.x releases added browser management: if Chrome is not installed, or if we ask for a specific version, it can download a Chrome for Testing build, a Chrome distribution made for automation that does not auto-update.
- Is a driver path set explicitly?YesUse that chromedriverNoCall Selenium Manager
- Is a browser version requested or Chrome missing?YesDownload Chrome for TestingNoDetect installed Chrome
- Matching chromedriver in cache or PATH?YesUse itNoDownload the matching driver
- Start chromedrivera local process with its own port
- Create the browser sessionW3C
WebDriverprotocol
5 steps in order. Play them, or step through them one at a time.
Notice that the first run on a fresh machine is slower, because the driver is downloaded; later runs use the cache. On CI agents without internet access, the cache can be pre-filled in the image, or the driver path can still be set explicitly.
3Matching and Pinning Versions
By default, Selenium Manager follows whatever Chrome is installed. On a developer laptop that is what we want. On CI it is a source of surprise: Chrome updates itself, and a test suite that passed yesterday may fail today because of a rendering or behaviour change in the browser, even though our code did not change.
There are two ways to pin. The first is to ask for a version in the options, which makes Selenium Manager fetch that version of Chrome for Testing and the matching driver. The second, common in larger setups, is a fixed container image with a specific Chrome and chromedriver installed, such as the official Selenium images, updated deliberately when we choose.
Either way, the browser version becomes part of our build configuration, and upgrading it is a reviewed change rather than something that happens overnight.
4Running Headless on CI
CI agents usually have no display, so we run Chrome headless, meaning without a visible window. We pass Chrome arguments through ChromeOptions.
The new headless mode runs the full Chrome browser without a window, so pages behave as they do for real users. The old headless mode was a separate implementation with small differences, and in recent Chrome versions plain --headless already selects the new mode; check your version. The window size matters more than it looks. Without it, headless Chrome uses a small default viewport, so a responsive page may show its mobile layout, hide a menu behind a hamburger button, and make a test that passes on a laptop fail on CI. Some container setups also need --no-sandbox or a larger shared memory size, but those belong to the container configuration, not to every test.
5Closing the Browser Every Time
Every ChromeDriver starts two processes, chromedriver and Chrome. If a test ends without calling quit(), both keep running. On a CI agent that runs hundreds of tests, leaked browsers pile up until the machine runs out of memory and unrelated tests start failing. So we create the driver before each test and quit it after each test, in a method that runs even when the test fails.
JUnit Jupiter runs @AfterEach even when the test fails, which is exactly what we need. In TestNG the equivalent is @AfterMethod(alwaysRun = true). Many teams move this into a small JUnit extension so every UI test class gets the same setup and cleanup without repeating it.
6Follow-up questions
What is the difference between quit() and close()?
close() closes the current window or tab. If it was the last window, the browser may exit, but the WebDriver session is not cleanly ended. quit() ends the whole session: it closes every window, shuts down Chrome and stops the chromedriver process. In test cleanup we use quit(); close() is for tests that open several windows and want to close one of them.
Do we still need WebDriverManager?
Usually not. Selenium Manager covers driver resolution and, in recent versions, browser downloads. WebDriverManager can still be useful in special setups, for example features it offers around Docker browsers, but for a plain local or CI run the built-in manager is enough and removes a dependency.
How do you run against a remote browser instead?
With RemoteWebDriver pointed at a Selenium Grid or a cloud provider: new RemoteWebDriver(new URL(gridUrl), options). Selenium Manager is not involved then, because the Grid node already has a browser and driver; the options still carry the headless setting, window size and requested browser version.
7Conclusion
In this answer, we saw that Selenium needs a chromedriver that matches Chrome, and that in recent Selenium 4 releases Selenium Manager resolves and caches it automatically, and can download Chrome for Testing when needed, so manual driver paths and WebDriverManager are mostly unnecessary. We pinned the browser version on CI with setBrowserVersion or a fixed image, ran headless with --headless=new and a fixed window size, and quit the driver after every test so no browser processes leak.
Open with
Today I just write new ChromeDriver with a ChromeOptions object. Behind that call, Selenium Manager, which is bundled with Selenium since 4.6, checks which Chrome is installed, finds or downloads the matching chromedriver, caches it, and in later 4.x versions it can also download a Chrome for Testing browser if none is installed or if I ask for a specific version.
Then, if they want more
So the old System.setProperty with a driver path, or the WebDriverManager library, is mostly unnecessary now. The version matching matters because each chromedriver supports one Chrome major version; a mismatch makes the session fail to start.
By default Selenium Manager follows the installed Chrome, which is fine on a laptop, but on CI Chrome auto-updates and can change behaviour overnight, so I pin it, either with options.setBrowserVersion or by using a fixed container image with a known Chrome and driver.
For CI I run headless with addArguments dash dash headless equals new, which is the full browser without a window, plus a fixed window size like 1920 by 1080, because otherwise headless Chrome uses a small viewport and responsive pages can switch to a mobile layout and break tests.
Finally, I always call driver.quit in @AfterEach, or @AfterMethod with alwaysRun in TestNG, because quit ends the session and closes both Chrome and chromedriver, while close only closes the current window; without quit, browser processes leak on the CI agent.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How do you start a Chrome browser from a Selenium 4 Java test today? Explain what...": https://scrivio-interview-library.netlify.app/java/ui-testing/639fbc862f/