How to run your Selenium Test Scripts on Firefox Browser

Last updated on Dec 02 2021
Manikaran Reddy

Table of Contents

How to run your Selenium Test Scripts on Firefox Browser

In this blog , we’ll find out how to run your Selenium Test Scripts on Firefox Browser.
Before proceeding with this section, allow us to first understand the fundamentals of Gecko Driver.

What is Gecko Driver?

The term Gecko refers to Gecko browser engine which was developed by Mozilla Foundation as a neighborhood of Mozilla browser.
Gecko Driver is a link between your tests in Selenium and therefore 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. albeit you’re working with older versions of Firefox browser, Selenium 3 expects you to line path to the driving force executable by the webdriver.gecko.driver.
Note: Selenium 3 has upgraded itself to now launch Firefox driver using Marionette driver rather than the default initialisation supported earlier.
Let us consider a test suit during which we’ll attempt to automate the subsequent scenarios in Firefox browser.
• Launch Firefox browser.
• Open URL: www.tecklearn.com
• Click on the Custom Search text box
• Type the worth “Java”
• Click on the Search button.
We will create our second test suit within the same test suite (Demo_Test).
Step1. Right click on the “src” folder and make a replacement Class File from New > Class.
Give your Class name as “Second” and click on on “Finish” button.

Selenium Web Driver
Selenium Web Driver
Selenium Web Driver
Selenium Web Driver

Step2. Open URL: https://github.com/mozilla/geckodriver/releases in your browser and click on on the acceptable version for GeckoDriver download supported the OS you’re currently performing on . Here, we are downloading the 64bit version of GeckoDriver for windows.

Selenium Web Driver
Selenium Web Driver

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

Selenium Web Driver
Selenium Web Driver

Before writing the test script, allow us to first understand how we will initialize GeckoDriver in Selenium. There are 3 ways to initialize GeckoDriver:
1. Using Desired Capabilities
First, we’ve to line the system property for Gecko Driver.

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

Below is that the code to line gecko driver using DesiredCapabilities class.

1. DesiredCapabilities capabilities = DesiredCapabilities.firefox();
2. capabilities.setCapability("marionette",true);

Here is that the complete code:

1. System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );
2. DesiredCapabilities capabilities = DesiredCapabilities.firefox();
3. capabilities.setCapability("marionette",true);
4. WebDriver driver= new FirefoxDriver(capabilities);

2. Using marionette property:
Gecko Driver also can be initialized using marionette property.

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

The code for Desired Capabilities isn’t required for this method.
3. Using Firefox Options:
Firefox 47 or later versions have marionette driver as a legacy system. Thus, marionette driver are often called using Firefox Options as shown below.

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

Step3. Now it’s time to code. we’ve embedded comments for every block of code to elucidate the steps clearly.

1. import org.openqa.selenium.By;
2. import org.openqa.selenium.WebDriver;
3. import org.openqa.selenium.firefox.FirefoxDriver;
4. import org.openqa.selenium.remote.DesiredCapabilities;
5.
6. public class Second {
7.
8. public static void main(String[] args) {
9.
10. // System Property for Gecko Driver
11. System.setProperty("webdriver.gecko.driver","D:\\GeckoDriver\\geckodriver.exe" );
12.
13. // Initialize Gecko Driver using Desired Capabilities Class
14. DesiredCapabilities capabilities = DesiredCapabilities.firefox();
15. capabilities.setCapability("marionette",true);
16. WebDriver driver= new FirefoxDriver(capabilities);
17.
18. // Launch Website
19. driver.navigate().to("http://www.tecklearn.com/");
20.
21. // Click on the Custom Search text box and send value
22. driver.findElement(By.id("gsc-i-id1")).sendKeys("Java");
23.
24. // Click on the Search button
25. driver.findElement(By.className("gsc-search-button gsc-search-buttonv2")).click();
26. }
27.
28. }

 

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

Selenium Web Driver
Selenium Web Driver

Step5. The output of above test script would be displayed in Firefox browser.
www.tecklearn.com
So, this brings us to the end of blog. This Tecklearn ‘How to run your Selenium Test Scripts on Firefox Browser’ blog helps you with commonly asked questions if you are looking out for a job in Selenium and Automation Testing. If you wish to learn Selenium and build a career in Automation Testing domain, then check out our interactive, Selenium Certification Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/selenium-training-certification/

Selenium Certification Training

About the Course

Tecklearn’s Selenium Certification Training enables you to master the complete Selenium suite. The Selenium Training is designed to train developers and manual testers to learn how to automate web applications with a robust framework, and integrate it within the DevOps processes of an organization. This Selenium Certification Training will also help you master important concepts such as TestNG, Selenium IDE, Selenium Grid, Selenium WebDriver, etc. Get hands-on experience on widely used automation frameworks such as Data-Driven Framework, Keyword-Driven Framework, Hybrid Framework, and Behavior Driven Development (BDD) Framework. Throughout this online Instructor-led Selenium Certification Training, you will be working on real-life industry use cases.

Why Should you take Selenium Certification Training?

• The average salary of a Selenium Test Automation Engineer is $94k per year – Indeed.com.
• Automation Testing Market is expected to grow at a Compound Annual Growth Rate (CAGR) of 18.0% in the next three years.
• Global software testing market to reach $50 billion by 2020 – NASSCOM. Selenium tool supports more browsers and languages than any other testing tool.

What you will Learn in this Course?

Getting started with Selenium
• Introduction to Selenium testing
• Significance of automation testing
• Comparison of Manual and Automation Testing
• Installation of Java JDK, JRE and Eclipse
Setting the environment in Eclipse for Selenium
• Java Introduction
• Creating a Java function and executing
• Concepts of Java
• Properties File
• Reading Data from Excel File
• Database Connection
• Hands On
Advantages of Selenium automation testing
• Selenium Features
• Concept of Selenium Integrated Development Environment
• Understanding of the Selenium IDE features
• Addition of Script assertions and general commands
• Deploying the first Selenium Script
• Sample project IDE
• Recording Selenium test case
• Hands On
Selenium Web driver Automation
• Architecture of Selenium Web Driver
• Download and installation
• Creating a Java function using Selenium and execution
• Hands On
Deploying Web Drivers for scripting
• Getting the HTML source of Web Element
• Table and Form Elements
• Firebug extension and Fire Path installation
• Advance User Interactions and Cross Browser Testing
• Hands On
Deep dive into Selenium Web Driver
• Action Commands
• Web Table / Date Picker
• How to Implement Switching Commands in WebDriver
• Alerts
• Frames
• Hands On
Switching Operations in WebDriver using Window
• Selenium Webdriver Wait
• Implicit wait, Explicit wait
• Deploying searching elements using the link text, name, using XPath
• Calendar
• Hands On
Introduction to TestNG Framework
• Introduction to TestNG
• Advantages of TestNG
• Installing TestNG on Eclipse
• Rules to write TestNG
• TestNG Features
• Annotations
• Grouping
• Sequencing: Prioritization and Dependency
• Enable/Disable a test case
• Parameterization: Using Xml file and DataProvider
• Parallel Testing & Cross Browser Testing
• TestNG Report: HTML Report, Console Report, XML Report
JUnit Operations and Test Framework
• Annotations, Methods in JUnit
• Junit Test Suites, ANT Build and JUNIT reporting
• Types of Test Automation Framework
• Module Based Testing Framework
• Data Driven Testing Framework
• Keyword Driven Testing Framework
• Hybrid Driven Testing Framework
• How to implement Testing Framework in Project
Object Repository
• Understanding of Object Repository
• Learning sample scripts using object repository
• Page Object Modelling
• Page Factory
JavaScript Functions
• Autosuggestion
• Headless Browser
• Sikuli
• XPath

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "How to run your Selenium Test Scripts on Firefox Browser"

Leave a Message

Your email address will not be published. Required fields are marked *