DEV Community

Cover image for 🔥 How to Create & Use Firefox Profile in Selenium?
Pramod Dutta
Pramod Dutta

Posted on

🔥 How to Create & Use Firefox Profile in Selenium?

Firefox's profile is one of the important feature about the Firefox, We need profile if we want to Customize out.

Why do we need a Firefox Profile?

To create your own automation profile that you can use in Automation.

Every time the same profile is used so that the download folder and other things are be cached or the same.

You can install custom add-on which are always available in the Firefox profile.

E.g. We are using a multi pass add-on which allows us to automatically bypass the basic auth popup.
How to create Firefox Profile?
Open the Firefox and open this URL “about:profiles”

Click on the create new profile.

Open that profile and install your favorite add-ons like ad blocker, multipass for this demo to work.

Firefox profile setup in selenium

How to Customize Download folder, and other add-on to Firefox profile?

You can customize the download folder if you are testing some download functionality in the selenium with the profile.

This is helpful in downloading and verifying file test cases, you can use the hard coded path in the profile every time.

Customize downloads, and added add-on are available in Profile every time you launch the profile with the Firefox profile options.

firefox profile with multipass extension

How to bypass Basic auth using Firefox Profile in Selenium?

Suppose you have a test case where you have to open a basic auth popup. Problem with the Basic auth is that it is popup and very hard to automate in Selenium.

You can’t directly use the driver.switchTo() method here.

Now You can use these methods

Method 1 :
Easy way to open the URL with the https://username:password@website.com , so the URL for the demo becomes https://admin:admin@the-internet.herokuapp.com/basic_auth

But for some websites it doesn’t work, We have to use certain add-ons to handle the popup, thankfully we have a plugin like multi pass where you can save the username, password and URL it will automatically put all the details.

Method 2:

So steps are

Just create a Profile with multi pass add-on and URL with details or credentials.
Open the URL in the same profile.
Multi pass will automatically put the credentials and login to the portal.
Verify the home page

package com.test1;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;

public class ProfileDemo {
    public static void main(String[] args) {
        ProfilesIni settings = new ProfilesIni();

        FirefoxProfile profile = settings.getProfile("thetestingacademy");


        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        WebDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("https://the-internet.herokuapp.com/basic_auth");
        System.out.println(driver.getPageSource());


    }
}

Want to become Automation RockStar ?

https://learn.thetestingacademy.com/

✅ API Testing using Postman -
https://www.learnapitesting.com

✅ Cypress Tutorial with LIVE Projects -
https://cypresstutorial.com

✅ REST API testing with Python -
https://masterapitesting.com

Top comments (0)