Today, I’m going to talk to you about a very important topic, which has to do with how to manage browser drivers within Selenium. Millions of years ago, in a far, far away galaxy, browser drivers used to be managed in this way.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
Just kidding! Maybe it wasn’t that long ago, but it sure feels like it, considering how fast things are moving these days. So, as you all know, we used to have to download the driver for each of the browsers that we wanted to use. Then, we would need to set a system property to tell Selenium where to find the driver. To make matters worse, we used to have to keep track of the new versions that came out. So, anytime a new version came out, you had to download that version.
To help ease the pain, WebDriverManager came in. This manager allows you to not have to worry about downloading the drivers and setting system properties. It simply manages the drivers automatically for you. So, we no longer have to download drivers and set system properties. It makes our lives so much easier.
But the exciting news is that you no longer need to use either one of these. Yes, you heard me right. You no longer need to have WebDriverManager or set a system property to set up a browser driver. Are you curious about how to do that? Let’s find out.
So, if you’re using Selenium 4.6.0 and above, you are able to do that already. As it turns out, Selenium 4.6.0 comes bundled with Selenium WebDriver, and they’re calling it Selenium Manager. So, you don’t need to have a separate dependency in your pom.xml file or WebDriverManager. All you need is the Selenium dependency, and you’re good to go. Let’s see how the code would look now.
WebDriver driver = new ChromeDriver();
Selenium will automatically take care of driver management.
Hope this was useful, enjoy testing and till the next time!