java webdriver 是一个类还是一个接口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32670288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:36:09  来源:igfitidea点击:

Is webdriver a class or a interface?

javaseleniumselenium-webdriverwebdriver

提问by Mainak Sikdar

From the Selenium docs, WebDriver is an Interface but in Eclipse the package org.openqa.seleniumis shown as a Class in the Project Explorer. Also, if WebDriver is an Interface, the classes like ChromeDriver or InternetExplorerDriver which implement it should be defining the methods like .get()or .getCurrentUrl(). Where can we see the method definition of these methods?

Selenium 文档中,WebDriver 是一个接口,但在 Eclipse 中,该包org.openqa.selenium在项目资源管理器中显示为一个类。此外,如果 WebDriver 是一个接口,那么实现它的 ChromeDriver 或 InternetExplorerDriver 等类应该定义像.get()或之类的方法.getCurrentUrl()。哪里可以看到这些方法的方法定义?

回答by Saifur

WebDriver is a public interface and I do not think ChromeDriver or any other driver implement WebDriver they rather extend RemoteWebDriverwhich is a class.

WebDriver 是一个公共接口,我不认为 ChromeDriver 或任何其他驱动程序实现了 WebDriver,而是扩展了RemoteWebDriver这是一个类。

Edit

编辑

As I have said the drivers extends RemoteWebDriver and that has the actual implementation of those method..

正如我所说,驱动程序扩展了 RemoteWebDriver 并且具有这些方法的实际实现..

public void get(String url) {
   execute(DriverCommand.GET, ImmutableMap.of("url", url));
}

Java source:

Java源代码:

public interface WebDriver extends SearchContext {
  // Navigation

  /**
   * Load a new web page in the current browser window. This is done using an HTTP GET operation,
   * and the method will block until the load is complete. This will follow redirects issued either
   * by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect
   * "rest" for any duration of time, it is best to wait until this timeout is over, since should
   * the underlying page change whilst your test is executing the results of future calls against
   * this interface will be against the freshly loaded page. Synonym for
   * {@link org.openqa.selenium.WebDriver.Navigation#to(String)}.
   *
   * @param url The URL to load. It is best to use a fully qualified URL
   */

回答by Prashant Tiwari

WebDriver is a public interface, we just define a reference variable(driver) whose type is interface. Now any object we assign to it must be a instance of a class (fireFoxDriver)that implement the interface.

WebDriver 是一个公共接口,我们只是定义了一个类型为接口的引用变量(驱动程序)。现在我们分配给它的任何对象都必须是实现该接口的类 (fireFoxDriver) 的实例。