×

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

Selenium Assertion

Selenium Assertion: In this section, we will learn about the Assertion in Selenium WebDriver. An Assertion is a feature available in TestNG, which is used to verify the expected result of...

7 minutes read.

WebDriver-Class Name Locator

WebDriver-Class Name Locator In this tutorial, we will learn about the Class name locator of selenium WebDriver. The Class Name locator is used to identify any element in UI based on the...

4 minutes read.

Id Locator in Selenium IDE

Id Locator Id locator is used to find the web element by the help of id of that element because ID is likely to be unique for each web element. Target Format: Id=id of the...

2 minutes read.

Selenium WebDriver – Web Element Controls

Selenium WebDriver – Web Element Controls A web element is an interface that is implemented by a remote web element class. The Web element control can be used to perform the data...

1 minute read.

Selenium IDE Tutorial for Beginners

Selenium IDE Introduction Selenium IDE stands for Integrated Development Environment. Selenium-IDE is released in 2006 and developed by SHINYA [JAPAN] THOUGHTWORK Company. Selenium IDE implemented as a Firefox plug-in, and concedes the record, edit, and debug tests....

2 minutes 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 - 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.

CSS Selector: ID/Class and Attribute in Selenium IDE

CSS SELECTOR: ID/Class and Attribute The Id, class, and attribute of CSS selector are used to identify the web element to access the web pages.  Syntax for Id/Class and Attribute: css= <./#> {[attribute=Value of...

2 minutes read.

Advantages and Disadvantages of Selenium-IDE

Advantages and Disadvantages of Selenium-IDE Advantages of Selenium IDE: UI based record and playback tool. Easy to understand & developed a test script. Selenium-IDE test script export into web driver code & Selenium–RC It is...

1 minute read.

CSS Selector: ID in Selenium IDE

CSS Selector: ID The id attribute is used to identify the web element uniquely in the web pages. Syntax of ID Attribute:  [HTML tag][#][Value of ID attribute] The hash sign (#): it is mandatory while using the...

1 minute read.

Name Locator in Selenium IDE

NAME LOCATOR: It is used to find the name in the web element. If we have multiple web elements of the same name, then the first matched element would be returned. Open the...

3 minutes read.

Selenium WebDriver-CSS Selector locator

Selenium WebDriver-CSS Selector locator A CSS selector is used to identify the web element based on their “# id” and “. Class”, Html tags, and attributes. A CSS stands for Cascading Style...

1 minute read.

Selenium Wait

In this tutorial, we will understand how we can avoid synchronization issues while executing the test script in a selenium WebDriver. Before going further in this tutorial, first, we will understand that...

10 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.

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.

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.

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.

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.

Drag and Drop Event Handling

Drag and Drop Event Handling: In this tutorial, we will learn how to handle the drag and drop event in selenium WebDriver using the action class. Before going further in this tutorial...

6 minutes read.

Selenium WebDriver-CSS Selector: Tag and Class

Selenium WebDriver-CSS Selector: Tag and Class We will locate the web element with the help of tag and class CSS selector in this section of the tutorials Where Tag and class are...

4 minutes read.