WebDriver is an Interface that defines the contract for browser automation. When we write `WebDriver driver = new ChromeDriver();`, we are using the concept of 'Upcasting' in Java (or polymorphism in general). This allows different browser implementations (Chrome, Firefox, Safari) to be swapped without changing the calling code. The WebDriver interface provides methods for finding elements, navigating, managing cookies, taking screenshots, and more.
WebDriver is like a universal remote control that works with all TV brands. The actual implementation (ChromeDriver, FirefoxDriver) is like the specific remote for each brand, but they all follow the same WebDriver contract.
Why do we write `WebDriver driver = new ChromeDriver();` instead of `ChromeDriver driver = new ChromeDriver();`?