Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

selenium - Difference between webdriver.firefox.marionette & webdriver.gecko.driver

I am now learning Selenium and have met a problem.

I am aware that Selenium supported old Firefox version by default without a driver. And for recent versions of Firefox, we have to download the driver and define it using System.setProperty.

According to this link, for Firefox 45 and 46, start driver code could look like this:

WebDriver driver = new FirefoxDriver();

My Firefox is version 45.5.1., but above code still won't work. So according to this link, I have added:

System.setProperty("webdriver.firefox.marionette","C:\geckodriver.exe");

And it worked.

Then I realized that I haven't installed geckodriver.exe on my computer. To see how it goes, I have changed to the code below:

System.setProperty("webdriver.firefox.marionette","");

It still works.

So, here comes my first problem: What happened? I am sure that no geckodriver.exe exists in my environment. If no location has been pointed, then why should I have to set property?

Also, I have seen code like:

System.setProperty("webdriver.gecko.driver", "/tools/marionette/wires.exe");

My second question is that what is the difference between webdriver.gecko.driver and webdriver.firefox.marionette or wires.exeand geckodriver.exe?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Up to version 45 (pushed to version 47), the driver used to automate Firefox was an extension included with each client. But this extension was dropped, probably due to the change of policy which now requires all the extensions to be signed by Mozilla.

Marionette is the new driver that is shipped/included with Firefox. This driver has it's own protocol which is not directly compatible with the Selenium/WebDriver protocol.

The Gecko driver (previously named wires) is an application server implementing the Selenium/WebDriver protocol. It translates the Selenium commands and forwards them to the Marionette driver.

For the Java client, the default behavior is to use the Gecko driver, but it can be overridden to use the legacy extension as a driver with the webdriver.firefox.marionette property:

System.setProperty("webdriver.firefox.marionette", "false");

or with the marionette capability through FirefoxOptions :

FirefoxOptions options = new FirefoxOptions()
  .setLegacy(true);

WebDriver driver = new FirefoxDriver(options);
// or with a remote server
WebDriver driver = new RemoteWebDriver(remoteUrl, options.toDesiredCapabilities());

or directly with the DesiredCapabilities:

DesiredCapabilities capa = DesiredCapabilities.firefox();
capa.setCapability("marionette", false);

WebDriver driver = new FirefoxDriver(capa);
// or with a remote server
WebDriver driver = new RemoteWebDriver(remoteUrl, capa);

And to define the location of the Gecko driver, either place the driver in a folder present in the PATH environment variable, or define the location in the property webdriver.gecko.driver:

System.setProperty("webdriver.gecko.driver", "C:\geckodriver.exe");

or launch a remote server with the property assigned in the command line:

java -Dwebdriver.gecko.driver="C:\geckodriver.exe" -jar selenium-server-standalone-3.4.0.jar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...