What Happens When You Execute new FirefoxDriver()
When you call new FirefoxDriver(), the following sequence happens in the background:
Step-by-step execution:
- ✓
geckodriver is located — Selenium finds the geckodriver executable via
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver") - ✓
geckodriver process starts — A new geckodriver process is launched on a local port (e.g., 4444 or random)
- ✓
Firefox binary is triggered — geckodriver launches the Firefox browser executable with default options
- ✓
New browser window opens — A fresh Firefox browser window appears with no extensions, no cookies, no history (clean profile)
- ✓
FirefoxDriver object is created — Java creates a
FirefoxDriverinstance that holds a connection to this browser via the WebDriver protocol (W3C JSON Wire Protocol) - ✓
Session is established — A unique session ID is created, allowing commands to be routed to that specific browser instance
Code sequence:
System.setProperty("webdriver.gecko.driver", "C://Drivers/geckodriver.exe");
// Step 1: Points to geckodriver binary
WebDriver driver = new FirefoxDriver();
// Steps 2-6: geckodriver launches → Firefox opens → connection established
driver.get("https://example.com");
// HTTP command sent via geckodriver to Firefox
Architecture:
Java Test ←→ geckodriver ←→ Firefox Browser
(sends W3C commands) (translates to Marionette protocol)
Summary:
- ✓Firefox binary is triggered
- ✓Firefox browser opens with default options
- ✓FirefoxDriver object is created and connected to the browser
- ✓The driver is ready to receive commands
