Sunteți pe pagina 1din 9

12/13/2018 Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox

(https://www.guru99.com/)

Home (/) Testing

SAP Web Must Learn! Big Data

Live Projects AI Blog (/blog/)

Gecko (Marione e) Driver Selenium: Download,


Install, Use with Firefox
What is Gecko Driver?
The term Gecko stands for a Web Browser engine that is inbuilt within Mozilla Firefox
browser. Gecko driver acts as a proxy between Web Driver enabled clients(Eclipse,
Netbeans, etc.) and Mozilla Firefox browser. In short, Gecko driver acts as a link between
Selenium Web Driver tests and Mozilla Firefox browser.

Before Selenium 3, Mozilla Firefox browser was the default browser for Selenium. After
Selenium 3, testers need to initialize the script to use Firefox using GeckoDriver explicitly.
Selenium uses W3C Webdriver protocol to send requests to GeckoDriver, which translates
them into a protocol named Marionette. Firefox will understand the commands transmitted in
the form of Marionette protocol and executes them.

(/images/1/030118_0746_GeckoMarion11.png)

Advantage of using Gecko Driver


Selenium Webdriver version 2.53 is not compatible with Mozilla Firefox version 47.0+. The
Firefox driver used in earlier versions of Mozilla Firefox will be discontinued, and only the
GeckoDriver implementation would be used. Hence testers are forced to use GeckoDriver if
they want to run automated tests on Mozilla Firefox version 47.0+. But the big question -
what is the advantage?

The major advantage of using GeckoDriver as opposed to the default Firefox driver is
Compatibility. GeckoDriver uses W3C WebDriver protocol to communicate with Selenium.
W3C is a universally defined standard for Web Driver. This means Selenium Developers
(People who code Selenium base) need not create a new version of Web Driver for each
browser version. The same Web Driver can be used for multiple browser versions. Hence,
GeckoDriver is preferred compared to the earlier implementation of Firefox driver.

https://www.guru99.com/gecko-marionette-driver-selenium.html 1/9
12/13/2018 Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox
Download and Install Gecko Driver:
Gecko Driver is available as an executable file that can be downloaded on the system. The
following are the list of steps to download gecko driver.

Step 1 ) At this page https://github.com/mozilla/geckodriver/releases


(https://github.com/mozilla/geckodriver/releases) ,Select the appropriate version for
GeckoDriver download based on your operating system

(/images/1/030118_0746_GeckoMarion1.png)

Step 2) Once the ZIP file download is complete, extract the contents of ZIP File onto a file
folder

(/images/1/030118_0746_GeckoMarion2.png)

Step 3) Note the location where you extracted the driver. Location will be used later to
instantiate the driver.

(/images/1/030118_0746_GeckoMarion3.png)

https://www.guru99.com/gecko-marionette-driver-selenium.html 2/9
12/13/2018 Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox
Ways to ini alize GeckoDriver:
There are three different ways to initialize GeckoDriver.

1. Using DesiredCapabilities:

First, set the system property for Gecko Driver.

Syntax:

System.setProperty("webdriver.gecko.driver","Path to geckdriver.exe file");

Example:

System.setProperty("webdriver.gecko.driver","D:\\Downloads\\GeckoDriver.exe");

Next, set Desired Capabilities.

Desired Capabilities help Selenium to understand the browser name, version and operating
system to execute the automated tests. Below is the code to set gecko driver using
DesiredCapabilities class.

DesiredCapabilities capabilities = DesiredCapabilities.firefox();


capabilities.setCapability("marionette",true);

Here is the complete code

System.setProperty("webdriver.gecko.driver", driverPath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
driver= new FirefoxDriver(capabilities);

2. Using marionette property:

Gecko driver can also be initialized using marionette property as below

System.setProperty("webdriver.firefox.marionette","D:\\Downloads\\GeckoDriver.exe");

If gecko driver is initialized using the above method, code for desired capabilities is not
required.

3. Using FirefoxOptions:
https://www.guru99.com/gecko-marionette-driver-selenium.html 3/9
Mozilla
12/13/2018 Firefox version 47+ has marionette
Gecko driver
(Marionette) Driver as aDownload,
Selenium: legacyInstall,
system. Taking
Use with Firefox advantage of

this, marionette driver can be called using Firefox Options as below

FirefoxOptions options = new FirefoxOptions();


options.setLegacy(true);

Code for launching firefox using Gecko driver :

package com.guru99.demo;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class GeckoDriverDemo {

String driverPath = "D:\\Guru99Demo\\GeckoDriver.exe";


public WebDriver driver;

@Before
public void startBrowser() {
System.setProperty("webdriver.gecko.driver", driverPath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);

@Test
public void navigateToUrl() {
driver.get("http://demo.guru99.com/selenium/guru99home/");
}

@After
public void endTest() {
driver.quit();
}

Code Explanation:

@Before method:

https://www.guru99.com/gecko-marionette-driver-selenium.html 4/9
Initially,
12/13/2018we need to set the system propertyDriver
Gecko (Marionette) for Selenium:
gecko Download,
driver to theUse
Install, geckdriver.exe
with Firefox file
download location. We need to set the marionette property to true for Selenium to use
Marionette protocol to communicate with Gecko Driver. Finally, we need to start the Firefox
browser instance using the object for Desired Capabilities.

The below statements help to achieve the above task.

System.setProperty("webdriver.gecko.driver", driverPath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette",true);
driver= new FirefoxDriver(capabilities);

@Test method:

We are navigating to user-specified URL using the inbuilt "get" method provided by
Selenium web driver. The below statement help to achieve the same.

driver.get("http://demo.guru99.com/selenium/guru99home/");

@After method:

Finally, we are closing the browser instance using the quit method.

driver.quit();

Modify a script for non- Gecko to Gecko:


Non-gecko driver script used before Selenium 3 was straightforward. We need to create an
instance of Firefox driver and use the instance variable.

@Before
public void startBrowser() {
driver = new FirefoxDriver();

To convert to gecko, you need to simply add one line of code

https://www.guru99.com/gecko-marionette-driver-selenium.html 5/9
12/13/2018 Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox
@Before
public void startBrowser() {
System.setProperty("webdriver.firefox.marionette", "D:\\Downloads\\GeckoDriver.ex
e");
driver = new FirefoxDriver();

Common excep ons occurred while using Gecko Driver:


Following is a list of common exceptions that occur while using Gecko Driver and with
resolution.

1. The path to driver executable must be set by webdriver.gecko.driver system


property:

This exception occurs when user tries to instantiate Firefox driver without setting the system
property for gecko driver. This is usually done by beginners to Selenium who are not aware
of the changes made from Selenium 3 to Selenium previous versions.

The resolution for the above exception is to set the system property for gecko driver with the
location of geckodriver.exe file as below

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

Please note that you need to set the property of gecko driver before creating an instance of
Mozilla Firefox driver.

2. Firefox Not Connected Exception:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on p


ort 7055 after 45000 ms.

This exception usually occurs when Firefox version has been upgraded to the latest version.
The resolution for this exception is to update the selenium jar file and gecko driver to the
latest version and use the same.

3. Session Not Created Exception:

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session.

https://www.guru99.com/gecko-marionette-driver-selenium.html 6/9
This exception
12/13/2018 occurs due to compatibility
Gecko (Marionette) issues between
Driver Selenium: Selenium
Download, and
Install, Use with Gecko driver.
Firefox

Gecko driver works with Firefox version 47 or above. It can be resolved by updating Firefox
version to 47 or above.

4. Connection Refused Exception:

WebDriver Exception: Connection Refused

This exception is the message generated when web driver is unable to establish a
connection with Firefox. It can be resolved using any one of the following techniques.

Use driver.quit() method to destroy earlier instances of web driver


Clean the browser cache before executing your automated tests
Clean the project workspace within Eclipse IDE
Always use the latest version of selenium gecko driver and most recent version of Firefox
browser

 Prev (/sikuli-tutorial.html) Report a Bug


Next  (/find-element-selenium.html)

YOU MIGHT LIKE:

SELENIUM SELENIUM SELENIUM

(/selenium- (/use-autoit- (/alert-popup-handling-


alternatives.html) selenium.html) selenium.html)
(/selenium- (/use-autoit- (/alert-popup-
alternatives.html) selenium.html) handling-
Top 15 Selenium How to use AutoIT with selenium.html)
Alterna ves in 2018 Selenium Alert & Popup Window
(/selenium-alternatives.html) (/use-autoit-selenium.html) Handling in Selenium
WebDriver
(/alert-popup-handling-
selenium.html)

SELENIUM SELENIUM SELENIUM

(/selenium-python.html) (/selenium-webtable.html) (/using-robot-api-


(/selenium- (/selenium- selenium.html)
python.html) webtable.html) (/using-robot-api-
selenium.html)
How to Use Selenium with How to Handle Web Table in
Python: Complete Tutorial Selenium WebDriver Robot Class in Selenium
(/selenium-python.html) (/selenium-webtable.html) Webdriver
https://www.guru99.com/gecko-marionette-driver-selenium.html 7/9
12/13/2018 (/using-robot-api-
Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox

selenium.html)

Selenium Tutorials
42) SSL Certificate Error Handling (/ssl-certificate-error-handling-selenium.html)

43) Handling Ajax call (/handling-ajax-call-selenium-webdriver.html)

45) Execute JavaScript based code (/execute-javascript-selenium-webdriver.html)

46) Using Selenium with Python (/selenium-python.html)

47) Use intelliJ & Selenium (/intellij-selenium-webdriver.html)

52) Flash Testing with Selenium (/flash-testing-selenium.html)

54) Core Extensions (/selenium-core-extensions.html)

55) Using Apache Ant with Selenium (/using-apache-ant-with-selenium.html)

56) Using Selenium with Github (/selenium-github.html)

57) Handling Cookies (/handling-cookies-selenium-webdriver.html)

58) Using SoapUI with Selenium (/using-soapui-selenium.html)

59) XSLT Report in Selenium (/xslt-report-selenium.html)

60) Firefox Profile (/firefox-profile-selenium-webdriver.html)

61) Breakpoints and Startpoints (/breakpoints-startpoints-selenium.html)

62) Selenium Interview Questions (/top-100-selenium-interview-questions-answers.html)

63) Cucumber Selenium (/using-cucumber-selenium.html)

64) Drag & Drop Selenium (/drag-drop-selenium.html)

65) Selenium C# Webdriver (/selenium-csharp-tutorial.html)

66) Creating Object Repository (/object-repository-selenium.html)

67) Scroll UP or Down a page (/scroll-up-down-selenium-webdriver.html)

68) Sikuli Tutorial (/sikuli-tutorial.html)

71) Selenium vs HP UFT (QTP) (/alm-qtp-selenium-difference.html)

72) Selenium Alternatives (/selenium-alternatives.html)

 (https://www.facebook.com/guru99com/) 
https://www.guru99.com/gecko-marionette-driver-selenium.html 8/9
12/13/2018

Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox
(https://twitter.com/guru99com)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)

(https://forms.aweber.com/form/46/724807646.htm)

About
About US (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact US (/contact-us.html)

Career Sugges on
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Certificates (/certificate-it-professional.html)

Interes ng
Books to Read! (/books.html)
Suggest a Tutorial
Blog (/blog/)
Quiz (/tests.html)
Review (/best-ergonomic-mouse.html)

Execute online
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html)

© Copyright - Guru99 2018


Privacy Policy (/privacy-policy.html)

https://www.guru99.com/gecko-marionette-driver-selenium.html 9/9

S-ar putea să vă placă și