×

Selenium WebDriver - Firefox or Gecko (Marionette) browser

Selenium web driver-Firefox or Gecko (Marionette) browser

In this tutorial, we are going to learn how to run the Selenium WebDriver test script in the Firefox Browser using the Gecko Driver.

Before going further with this segment, let us first understand the basics of a Gecko Driver.

What is the Gecko Driver?

The gecko driver is a web browser that is used in the developed application by the Mozilla Firefox browser. And it is produced by Mozilla Corporation and Mozilla Foundation.

Gecko Driver lies between our tests script in Selenium and the Firefox browser as a link.

It is a substitute between the W3C WebDriver-compatible clients like Eclipse, NetBeans, etc. to interact with Gecko-based browser (Mozilla Firefox).

Marionette (the next generation of Firefox Driver) is turned on by default from Selenium 3.

Selenium uses the W3C Web driver protocol to send requests to the Gecko Driver, which translates them into a protocol named Marionette.

Even if you are working with older versions of the Firefox browser, Selenium 3 expects you to set the path to the driver executable by the webdriver.gecko.driver.

Note: To open the Firefox driver, we will use the marionette driver instead of the default initialization, which is supported earlier.

We will create a test case in the same test suite (new_test), which we created in the previous tutorials of selenium WebDriver.

Step1:

  • Firstly, right-click on the src folder and create a new Class File from New ? Class.
Selenium web driver-Firefox or Gecko Marionette browser
  • And give your Class name as Test_gecko and click on the Finish button.
Selenium web driver-Firefox or Gecko Marionette browser 1

Step2:

  • Click on the below link, and it will navigate you to the download page of the Gecko driver in your browser.

https://github.com/mozilla/geckodriver/releases

  • Here, you can download the latest version of the Gecko driver and installed it based on the operating system which you are currently working on.

 So, we are downloading the 64bit version for the v0.25.0 release of the Gecko Driver for windows.

Selenium web driver-Firefox or Gecko Marionette browser 2
  • Download the zip file into your local system and unzip the folder, and it will generate the geckodriver.exe file automatically.
Selenium web driver-Firefox or Gecko Marionette browser 3

We have three ways to use Gecko Driver in selenium WebDriver:

1. Set the system property for gecko driver:-

Run the server before launching the Firefox browser, with the help of System.property.

Syntax:

System.SetProperty(“key”, ”value”);

Where,

Key = webdriver.gecko.driver

And the path of our geckoDriver.exe file to invoke the GeckoDriver class is as shown below,

Value= C:\Users\JTP\Downloads\geckodriver-v0.25.0-win64\geckodriver.exe

Here, is the sample code to set the system property,

// System Property for the gecko Driver
System.setProperty("webdriver.gecko.driver","C:\Users\JTP\Downloads\geckodriver-v0.25.0-win64\geckodriver.exe");
// create an object for Firefox Driver class.
WebDriver driver=new FirefoxDriver();

Or

Using Desired Capabilities:-

Here, the code to set the Gecko driver using Desired Capabilities class:

DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette",true);

Sample code for the desired capabilities:

System.setProperty("webdriver.gecko.driver"," C:\Users\JTP\Downloads\geckodriver-v0.25.0-win64\geckodriver.exe " );
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette",true);
WebDriver driver= new FirefoxDriver(cap);

2. Using marionette property:-

It can also be initialized using the marionette property.

System.setProperty("webdriver.firefox.marionette","
C:\Users\JTP\Downloads\geckodriver-v0.25.0-win64\geckodriver.exe ");
  • Code for Desired Capabilities is not mandatory for the marionette method.

3. Using Firefox Options:-

Marionette driver has a legacy system for Firefox 47 or later versions. And, the marionette driver can be called using Firefox Options, which is shown below,

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

Now, let us see one sample test case in which we will try to automate the following scenarios in the Firefox browser.

Steps Action Method Used Input Excepted Result
1. Open the Firefox Browser. System.setProperty()   The Firefox browser must be opened.
2. Navigate to the Given URL of the website. get() https://www.facebook.com/ The home page window of Facebook application must be displayed.
3. Identify the username text box and passing the value for it.     The username text box should be identified, and the value should be passed.
4. Identify the password text box and passing the value for it.     The password text box should be identified, and the value should be passed.
5. Close the Browser. close()   The browser should beterminated.

Here is the sample code for the above example,

package testpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test_gecko {
public static void main(String[] args) throws InterruptedException {
// set the system property for gecko driver
System.setProperty("webdriver.gecko.driver","C:\Users\JTP\Downloads\geckodriver-v0.25.0-win64\geckodriver.exe");
// create driver object for gecko browser
WebDriver driver=new FirefoxDriver();
 // Launch the Website  
driver.navigate().to("https://www.facebook.com/"); 
// pass the value to the email text box
driver.findElement(By.id("email")).sendKeys("hello world!");
Thread.sleep(2000);
System.out.println("msg printed");
// pass the value to the password text box
driver.findElement(By.name("pass")).sendKeys("123456"); 
Thread.sleep(2000);
System.out.println("passed");
//close the browser
 driver.close();
}
} 
  • Now, right-click on the Eclipse code and select Run as ? Java Application.

The output of the above test script would be displayed in the Firefox browser.

Selenium web driver-Firefox or Gecko Marionette browser 4
  • The output of all print command of the above test script would be displayed in the Eclipse console window.
Selenium web driver-Firefox or Gecko Marionette browser 5

 

 


Related Topics

Link Text Locator in Selenium IDE

LINK TEXT Link textlocator is used to identify only the weblink element based on the name of the link. Whenever multiple links are there, it will not work; it will work only...

1 minute read.

Selenium WebDriver - Browser Controls Commands

Selenium WebDriver - Browser Controls Commands WebDriver includes operations like opening a browser, fetch the title, and closing the browser, etc. Some of the most commonly used Browser controls commands for Selenium WebDriver...

6 minutes read.

Selenium WebDriver Tutorial

Seleniun WebDriver Introduction Selenium WebDriver is the essential tool of Selenium Tool Suite because it can directly communicate the browser without any server.  Selenium WebDriver is a browser automation framework that accepts...

3 minutes read.

WebDriver Interface | Class Diagram

WebDriver interface/class diagram: The interface of WebDriver includes the following stages, which is as follows: Search Context Web driver Remote web driver Driver class Search Context  The first interface of the web driver class is search Context,...

2 minutes read.

Selenium Tool Suite

The selenium tool suite is a combination of multiple software tools, and the entire tools having a different approach to support automation testing. Selenium test tool suites are as follows- Selenium...

2 minutes read.

Selenium WebDriver - IE [Internet Explorer] browser

Selenium WebDriver - IE [Internet Explorer] browser In this segment, we will understand how to run a test script with the help of the IE (Internet Explorer) browser. It is a standalone...

4 minutes read.

Selenium WebDriver-Alert Popup

Selenium WebDriver-Alert Popup  An alert popup is one of the small message boxes, which used to give some information to the user that displays on the browser. The Alert popup will be...

6 minutes read.

Selenium WebDriver-Locators

Selenium WebDriver-Locators The WebDriver uses the same set of locating strategies like selenium -IDE for specifying the location of the web element. Each locating strategy has its command in Java to locate...

1 minute read.

Selenium-IDE Login test

Login test for Selenium-IDE Now we are learning, how to create a Login/sign-up Test case in Selenium IDE. For our testing purpose, we are going to test the login page provided by...

2 minutes read.

WebDriver-Link Text locator

WebDriver-Link Text locator The Link text locator is used to identify only web link elements based on the value of the link. The Link text locators cannot be used for other than...

4 minutes read.

Selenium-IDE Locators

Selenium-IDE Locators: Before we start learning about Selenium –IDE Locators, firstly we have to learn about UI elements. UI Elements -UI elements are the elements which are displayed on the web application....

1 minute read.

CSS Selector: Attribute in Selenium IDE

CSS Selector: Attribute Locating the attribute of a CSS selector, we would access the Password textbox, which is present in the login form of Facebook. The Password textbox has a type attribute...

1 minute read.

Selenium WebDriver-CSS Selector: Substring Matching

CSS Selector: Substring Matching Selenium WebDriver In this tutorial, we will learn how to identify the web element using the substring method. A Sub-string contains three methods for identifying the web element...

9 minutes read.

Difference between Selenium WebDriver and Selenium RC

Difference between Selenium WebDriver, and Selenium RC: Selenium WebDriver and selenium RC (Remote Control) both are different in any manners which we see later in this tutorial, let us see the...

3 minutes read.

Selenium WebDriver Commands

Selenium WebDriver Commands: As we learn previously in the Selenium-IDE tutorial, Selenium commands are the set of commands that are used to run a Selenium test script. But whereas, Selenium WebDriver had...

2 minutes read.

Selenium WebDriver - Google Chrome Browser

Selenium WebDriver - Google Chrome Browser In this tutorial, we will learn how to run our Selenium Test Scripts in the Google Chrome Browser. To implement the WebDriver protocol with the help...

3 minutes read.

Selenium WebDriver- Checkbox handling

Selenium WebDriver- Checkbox handling In this tutorial, we will be learning about handling the checkbox in selenium WebDriver. Let us take one example to give you a better understanding of Checkbox handling,...

4 minutes read.

WebDriver-Id Locator

WebDriver-Id Locator: The Id Locator is used to identify any web element in UI with the help of the ID attribute. The First preference is always goes to ID locator while inspecting...

4 minutes read.

CSS Selector: Inner text in Selenium IDE

CSS Selector: Inner text The inner text is used to identify and create a CSS Selector using a string pattern of the HTML tag which is displayed on the web page. Syntax...

1 minute read.

WebDriver-Partial Link Text locator

WebDriver-Partial Link Text locator In selenium WebDriver, there is an additional way to find a web link element with the help of partial link text locator. The partial link text is used...

4 minutes read.