Every time we run a web test from Selenium we have to manually set the path of the Chrome Driver exe and then run the test.
But what if we can run it without setting the path in the System .setProperty!!
Yes it is possible. It is easy and simple. First go to maven repository and search for webdrivermanager. Click on the first link and pick the maven dependency. I have used 3.7.1 version.
Clean and build the project and the maven dependencies should show the one added.
That's all . You are now set to test the website without the setProperty. Now go to your code or create a new testNG class.
In BeforeTest method, provide the following line in the beginning
WebDriverManager.chromedriver().setup();
This ensures that your webdriver manager uses the chromedriver for the test.
The next two lines are used to initialize your webdriver and open the website.
Right click on file and run as TestNG
That's it. You will be able to see the chrome open as usual now with just a difference of omitting the System.setProperty(). You can use this approach for any browser.
Say goodbye to the System.setProperty.
Happy testing!!