Using different Firefox profiles

Last edited on

Overview

Firefox allows only one running instance of itself per Firefox profile. To execute further instances of Firefox at the same time the additional instances must each be configured to use a different Firefox profile.

Creating additional Firefox profiles

Step 1 - Create the desired Firefox profiles. (Close Firefox, start cmd.exe, execute "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P (in cmd.exe) to start Firefox with the Profile Manager. Create a profile.)

Step 2 - Use the profile with Firefox at least once to initialize it. ("C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P profile_name_here)

Step 3 - Close Firefox.

Step 4 - Explicitly switch back to the “normal” profile to make it the default again. ("C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -P, select profile, check Use the selected profile without asking at startup, click Start Firefox).

Step 5 - Close Firefox.

Step 6 - Run Squish’ setup again to register the required Squish extension in all profiles again, including the new one.

Prepare switching of Firefox profiles

Step 1 - Create one copy of %appdata%\Mozilla\Firefox\profiles.ini for every profile that you need (including the default profile). (For example profile.ini.default, profiles.ini.squish_profile, etc.)

Step 2 - In each of the copies of profile.ini move the line…

Default=1

…to the profile entry that this copy of profile.ini is meant for.

Use custom Squish for Web package

Use a Squish for Web package with a simple patch that adds “-no-remote” as an additional parameter to firefox.exe. (This is required to make Firefox really switch to the profile. When not specified it will just instruct the already running Firefox instance to show a new window.) Please contact Squish technical support to obtain such a package.

Switch Firefox Profiles in Test Script

To switch to a profile simply copy “profiles.ini.xyz” over “profiles.ini”, then start the browser. Here is an example script that does that:

import os.path
import shutil

def main():
    new_firefox_instance("www.froglogic.com", "squish_profile")

def new_firefox_instance(url, profile_name="default"):
    firefox_settings_dir = os.path.expandvars(r"$appdata\Mozilla\Firefox")

    ###########################
    #  ADJUST THESE FILE NAMES:
    ###########################
    profiles = {
            "default": "profiles.ini.default",
            "squish_profile": "profiles.ini.squish_profile"
        }

    # Set up desired profiles.ini file:
    source = os.path.join(firefox_settings_dir, profiles[profile_name])
    source_default = os.path.join(firefox_settings_dir, profiles["default"])
    target = os.path.join(firefox_settings_dir, "profiles.ini")
    try:
        shutil.copy(source, target)
    
        startApplication("__squish__webhook")
        loadUrl(url)

        # Restore default profiles.ini file:
        shutil.copy(source_default, target)
    except:
        # Really restore default profiles.ini file:
        shutil.copy(source_default, target)
        raise
test.py

Related Information