Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to set the System Property for Chrome And IE Browser and Not For Firefox Browser

For Chrome,

public class Chrome {

  public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
        WebDriver driver = new ChromeDriver();              
        driver.get("http://www.google.com");

    }

}

for Firefox,

public class Firefox {

      public static void main(String[] args) {

            WebDriver driver = new FirefoxDriver();              
            driver.get("http://www.google.com");

        }

    }

Why do we need to specify the system.setProperty for Chrome and IE?

like image 810
SacTan Avatar asked Feb 09 '16 06:02

SacTan


People also ask

Why do we need to set system property in Selenium?

Once the driver is downloaded for a specific browser, QAs need the setProperty() method to define the path for that driver before writing any test cases. This helps the Selenium WebDriver identify the browser on which tests are to be executed.

Why is a browser driver not needed in Mozilla Firefox?

It is just an extension that is created and used to communicate with Firefox, the other browsers & drivers simply don't follow the same implementation and thus, you are required to start drivers & executables for the others.

What is system set property?

Thus, the System. setProperty method is used to configure the browser driver path. The Selenium client library communicates with the ChromeDriver via the JSON Wire Protocol. The Chrome browser driver acts like a link between the Selenium implementation code and the Chrome browser.


2 Answers

I had also same question, but after digging I found,

WebDriver uses native browser approach. Selenium offers inbuilt driver for Firefox but not for other browsers. All drivers (Chrome Driver, IE driver, etc.) are built based on the special JS Engine used by each browser.

Selenium WebDriver works very well with Mozilla Firefox because it has a built in driver server. But the same is not true for Internet Explorer and Google Chrome. Firefox is the most traditional browser, thus Selenium WebDriver do not require any additional utility to be set before launching the browser. The Selenium package automatically references towards the default location of the firefox.exe, thus the user need not to set any other property.

If you ever get the “the path to the driver executable must be set by the webdriver. ie. driver system property” error or its similarly worded Chrome equivalent, it means that you need to install the driver servers on your browser. The driver server manages the calls between the browsers and the Selenium wire protocol.

The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol

Similarly, Google Chrome doesn’t have a built-in server so you will need a Chrome driver server for communicating your Selenium code to the browser. You can download the Chrome driver server.

Founded from here.

like image 146
Sanjay Bhimani Avatar answered Nov 08 '22 19:11

Sanjay Bhimani


Implementation of FirefoxDriver, ChromeDriver, InternetExplorerDriver is different, thus the way of instantiating the object differs as well.

The Firefox Driver controls the Firefox browser using a Firefox plugin. The Firefox Profile that is used is stripped down from what is installed on the machine to only include the Selenium WebDriver.xpi

The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol.

The ChromeDriver is maintained / supported by the Chromium project iteslf. WebDriver works with Chrome through the chromedriver binary (found on the chromium project’s download page). You need to have both chromedriver and a version of chrome browser installed. chromedriver needs to be placed somewhere on your system’s path in order for WebDriver to automatically discover it. The Chrome browser itself is discovered by chromedriver in the default installation path

For more details, refer the selenium documentation

like image 37
Amanpreet Kaur Avatar answered Nov 08 '22 20:11

Amanpreet Kaur