Theory done. Time to build. These exercises take you from zero to a working cross-browser test setup. Do them in order — each one builds on the previous.
Exercise 1: Build the WebDriver Factory
Create a WebDriverFactory class that supports chrome, firefox, and edge
Add Grid support — if grid.url system property is set, use RemoteWebDriver
Add headless support — if headless system property is true, enable headless mode
Test locally: run a simple test on Chrome, then Firefox, then Edge
Verify each browser opens, navigates to a URL, and quits cleanly
Exercise 2: Set Up Cross-Browser TestNG Suite
Create a BaseTest class with ThreadLocal<WebDriver> and @Parameters({"browser"})
Write a LoginTest that extends BaseTest — test login on the Banking Portal
Create testng-crossbrowser.xml with three <test> blocks (Chrome, Firefox, Edge)
Set parallel="tests" and thread-count="3"
Run it: mvn clean test -DsuiteXmlFile=testng-crossbrowser.xml
Start the Grid: docker compose -f docker-compose-grid.yml up -d
Open http://localhost:4444/ui — verify all 3 nodes are registered
Run your tests on Grid: mvn clean test -DsuiteXmlFile=testng-crossbrowser.xml -Dgrid.url=http://localhost:4444
Watch sessions appear on the Grid dashboard during execution
Scale Chrome to 3 nodes: docker compose up -d --scale chrome-node=3
Tear it down: docker compose down
Exercise 4: BrowserStack Integration
Create a free BrowserStack account
Set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY as env variables
Write a test that runs on Safari on macOS using BrowserStack
Run it and check the BrowserStack dashboard — watch the video recording
Enable network logs and console logs in capabilities
Try testing your localhost app using BrowserStack Local tunnel
Exercise 5: Headless CI Simulation
Modify WebDriverFactory to accept headless mode via system property
Run tests in headless mode: mvn clean test -Dheadless=true
Verify tests pass — compare execution time with headed mode
Take a screenshot in headless mode — confirm it captures the page correctly
Run headless tests on Docker Grid to simulate a CI environment
Do Exercise 1-2 first. Get them working locally. Then move to Docker (Exercise 3). BrowserStack (Exercise 4) is optional if you don't want to create an account. Headless (Exercise 5) is quick and valuable for CI understanding.
Key Point: Build the factory, wire up TestNG, run on Docker Grid, try BrowserStack, simulate CI with headless. Each exercise builds on the last.