Selenium WebDriver automation tool is mainly useful to run tests against multiple Browsers such as Chrome Browser,Firefox Browser,Internet Explorer Driver.Running the tests against multiple browsers is known as Cross Browser Testing.
To launch the Browser in Selenium WebDriver we need to set the path of the executable available in the laptop. Following that we have to instantiate the driver instance based on the Driver instance. In order to avoid these steps we can use the WebDriverManager class.
WebDriverManager
WebDriverManager allows to automate the management of the binary drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
Using WebDriverManager its not required to maintain the below lines of the code for launching the browser.
System.setProperty(“webdriver.chrome.driver”, “executable path”);
System.setProperty(“webdriver.gecko.driver”, “executable path”);
System.setProperty(“webdriver.opera.driver”, “executable path”);
System.setProperty(“phantomjs.binary.path”, “executable path”);
System.setProperty(“webdriver.edge.driver”, “executable path”);
System.setProperty(“webdriver.ie.driver”, “executable path”);
WebDriverManager Maven Depdendency
To use the WebDriverManager class ensure the following depedency is added in the maven project object model (pom.xml) file.
1 2 3 4 5 |
<dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>3.2.0</version> </dependency> |
Like our Facebook Page to get frequent updates->
https://www.facebook.com/totalqa
Selenium WebDriver Code
Execute the below code in eclipse and verify the results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.Test; import io.github.bonigarcia.wdm.WebDriverManager; public class GoogleTests { @Test public void verifyTitle() { WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver(); driver.get("http://www.total-qa.com"); String actual = driver.getTitle(); String expected="Total-QA - Future of Software Testing"; Assert.assertEquals(actual,expected); } } |