why we assign firefoxdriver instance to webdriver

前端 未结 8 1624
时光说笑
时光说笑 2021-02-06 16:52

I am novice to Java or Selenium.

I just need help to understand one basic question.

Why we assign firefoxdriver instance to WebDriver? WebDriver driver=new Firef

8条回答
  •  感情败类
    2021-02-06 17:23

    It will make use of Interface Concept.See the below code.

     FirefoxDriver  f = new FirefoxDriver();
     ChromeDriver c = new ChromeDriver();
    

    To load a page using chrome,

    c.get("google.com");

    If I want to use same call with firefox, I need to comment the above line and need to write a new line like this

    //c.get("google.com");
    f.get("google.com");
    

    This will go on increasing , ending up with specific code for each instance of driver. But if I assign the the driver instance to WebDriver interface variable, I can write single set of code which will work for all drivers.

     WebDriver d;
        d  = FireFoxDriver();
        //just replace the above line with d = ChromeDriver() or InternetExplorer();
        d.get("google.com");
        d.getTitle();
        d.close();
    

提交回复
热议问题