TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Selenium Webdriver Running Test on Firefox Browser Gecko Driver

Selenium Webdriver Running Test on Firefox Browser Gecko Driver with Introduction, features, selenium basic terminology, what is selenium, selenium limitations, selenium vs qtp, tool suite, selenium ide, ide-installation, ide-features, ide-first test case, ide-commands, ide-creating test cases manually, ide-login test etc.

<< Back to SELENIUM

Selenium WebDriver- Running test on Firefox Browser- Gecko (Marionette) Driver

In this section, we will learn how to run your Selenium Test Scripts on Firefox Browser.

Before proceeding with this section, let us first understand the basics of Gecko Driver.

What is Gecko Driver?

The term Gecko refers to Gecko browser engine which was developed by Mozilla Foundation as a part of Mozilla browser.

Gecko Driver serves as a link between your tests in Selenium and the Firefox browser. It acts as a proxy between W3C WebDriver-compatible clients (Eclipse, Netbeans, etc.) to interact with Gecko-based browser (Mozilla Firefox).

Marionette (the next generation of FirefoxDriver) is turned on by default from Selenium 3. Selenium uses W3C Webdriver protocol to send requests to GeckoDriver, which translates them into a protocol named Marionette. Even if you are working with older versions of Firefox browser, Selenium 3 expects you to set path to the driver executable by the webdriver.gecko.driver.

Note: Selenium 3 has upgraded itself to now launch Firefox driver using Marionette driver instead of the default initialisation supported earlier.

Let us consider a test case in which we will try to automate the following scenarios in Firefox browser.

  • Launch Firefox browser.
  • Open URL: www.TheDeveloperBlog.com
  • Click on the Custom Search text box
  • Type the value "Java"
  • Click on the Search button.

We will create our second test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class.

Give your Class name as "Second" and click on "Finish" button.


Selenium WebDriver Running test on Firefox Browser Gecko Driver
Selenium WebDriver Running test on Firefox Browser Gecko Driver

Step2. Open URL: https://github.com/mozilla/geckodriver/releases in your browser and click on the appropriate version for GeckoDriver download based on the operating system you are currently working on. Here, we are downloading the 64bit version of GeckoDriver for windows.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Before writing the test script, let us first understand how we can initialize GeckoDriver in Selenium. There are three ways to initialize GeckoDriver:

1. Using Desired Capabilities

First, we have to set the system property for Gecko Driver.

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

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","D:\\GeckoDriver\\geckodriver.exe" );
		DesiredCapabilities capabilities = DesiredCapabilities.firefox();
		capabilities.setCapability("marionette",true);
		WebDriver driver= new FirefoxDriver(capabilities);

2. Using marionette property:

Gecko Driver can also be initialized using marionette property.

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

The code for Desired Capabilities is not required for this method.

3. Using Firefox Options:

Firefox 47 or later versions have marionette driver as a legacy system. Thus, marionette driver can be called using Firefox Options as shown below.

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

Step3. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Second {

	public static void main(String[] args) {
		
		  // System Property for Gecko Driver 
System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );
		
		  // Initialize Gecko Driver using Desired Capabilities Class
	DesiredCapabilities capabilities = DesiredCapabilities.firefox();
	capabilities.setCapability("marionette",true);
	WebDriver driver= new FirefoxDriver(capabilities);
		
		 // Launch Website
	driver.navigate().to("http://www.TheDeveloperBlog.com/");
		
		// Click on the Custom Search text box and send value
	driver.findElement(By.id("gsc-i-id1")).sendKeys("Java");
		
		// Click on the Search button
driver.findElement(By.className("gsc-search-button gsc-search-buttonv2")).click();	
		}

}

The Eclipse code window will look like this:


Selenium WebDriver Running test on Firefox Browser Gecko Driver

Step4. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver Running test on Firefox Browser Gecko Driver

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


Selenium WebDriver Running test on Firefox Browser Gecko Driver




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf