Can we use ChromeDriver driver = new ChromeDriver() instead of WebDriver driver = new ChromeDriver()? If yes, what is the disadvantage?

We generally do it this way because usually we want to be able to run our tests on multiple browsers. If we declare the driver as a specific driver type, we are then anchored to only that driver. This is not a problem if you only ever need to test on say Chrome for example. But what if you later want your tests to also be able to work with IE, Opera, Firefox, etc.?

These are extended classes of the WebDriver interface.

If your main tests and other classes define the commonly shared driver as simply WebDriver instead of specifically being tied to ChromeDriver, then the same tests can be run without change to the test code itself simply by initializing the shared driver object with a different driver extended class.

Comments

Popular posts from this blog

Jenkins CICD in One Page

Why do we need a build tool?

Deutsche Bank Interview Questions - 2024