In this article, we will learn what is selenium webdriver. Selenium WebDriver was the first cross-platform testing framework that could configure and control the browsers on the OS level. It served as a programming interface to create and run test cases.
What Is Selenium WebDriver?
WebDriver performs actions on web elements. It supports various programming languages like Java, C#, PHP, Python, among others. It can also be integrated with frameworks like TestNG and JUnit for test management.
Selenium WebDriver supports multiple web browsers to test and run applications on.
We have to download separate drivers and we have to specify the path as well with the location of the driver.
WebDriver is an interface (interface have only function prototype). We cannot create Object of an Interface. If we create object of WebDriver, we will get compile time error (“Cannot instantiate the type WebDriver”).
1) ChromeDriver
The most common web browser used today is Google Chrome. Google Chrome is widely used globally, making it essential for all the websites on Chrome to be tested.
ChromeDriver driver = new ChromeDriver ();
We are creating instance of ChromeDriver. As per the java concept if We create an object using New keyword it will initiate constructor of that class. We have object of ChromeDriver class.
In this case our driver object will access all the methods implemented in ChromeDriver class. Also, it has access to all the methods of WebDriver and SearchContexts interfaces which is implemented in RemoteWebDriver as ChromeDriver class is extending.
WebDriver driver = new ChromeDriver ();
We are creating an instance of the WebDriver interface and casting it to ChromeDriver.
2) FireFoxDriver
FireFoxDriver driver = new FireFoxDriver ();
We are creating instance of FireFoxDriver. As per the java concept if We create an object using New keyword it will initiate constructor of that class. We have object of FireFoxDriver class.
In this case our driver object will access all the methods implemented in FireFoxDriver class. Also, it has access to all the methods of WebDriver and SearchContexts interfaces which is implemented in RemoteWebDriver as FireFoxDriver class is extending.
WebDriver driver = new FireFoxDriver ();
We are creating an instance of the WebDriver interface and casting it to FireFoxDriver.
What is System.getProperty() And System.setProperty()?
1) What is System.getProperty()?
The method is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is “user.dir”.
Program
String path=System.getProperty(“user.dir”);
System.out.println(“Driver Path:” +path);
OutPut
Driver Path: E: AccelerationSoftwareMavenPath_Maven Project
2) What is System.setProperty()?
The setProperty method enables QAs to set the properties for the desired browser to be used in test automation.
The setProperty method has two attributes – “propertyName” and “value.” The propertyName represents the name of the browser-specific driver, and the value points to the path of that browser driver.
System.setProperty(“webdriver.chrome.driver”, path+”\drivers\chromedriver.exe\”);