Selenium Firefox Profil: Kurulum Kılavuzu

⚡ Akıllı Özet

Firefox profile stores the bookmarks, passwords, add-ons and preferences that belong to one browser user, and Selenium WebDriver can load a dedicated profile so every automated run starts from an identical, predictable browser state.

  • 🔘 Profile basics: A Firefox profile holds one user’s bookmarks, saved passwords, add-ons, certificates and preferences in a single folder.
  • ☑️ Profile location: Windows, Linux ve macOS each store profile folders under a different path inside the user directory.
  • Profil oluşturma: The built-in profile manager opens with firefox.exe -p and builds a clean automation profile in five steps.
  • 🧪 Code Giriş: The ProfilesIni class reads profiles.ini, and getProfile returns the named profile as a FirefoxProfil nesnesi.
  • Current syntax: Selenium 3 and 4 pass the profile through FirefoxOptions.setProfile rather than the FirefoxDriver constructor.
  • ⚠️ Tercihler: setPreference controls the download folder, notifications, language and certificate handling before the browser launches.

Selenium Firefox Profile setup guide

Selenium Firefox Profil

Firefox profil, üzerinde yapılabilecek ayarlar, özelleştirme, eklentiler ve diğer kişiselleştirme ayarlarının toplamıdır. Firefox Browser. Kişiselleştirebilirsiniz Firefox profilinize uygun Selenium otomasyon gereksinimi.

Ayrıca, Firefox veya başka herhangi bir tarayıcı SSL sertifikalarının ayarlarını yönetir. Dolayısıyla bunları otomatikleştirmek, test yürütme koduyla birlikte çok anlamlıdır.

In short a profile is a user’s personal settings. When you want to run a reliable otomasyon Bir on Firefox browser, it is recommended to make a separate profile. A dedicated profile also keeps your everyday browsing data out of the test run, which is the first thing to rule out when a Selenium script behaves differently on two machines.

Profil klasörünüzün diskteki konumu

Firefox profil tıpkı farklı kullanıcıların kullandığı gibidir Firefox. Firefox saves personal information such as bookmarks, passwords, and user preferences which can be edited, deleted or created using the profile manager.

The screenshot below shows a profile folder as it appears on disk, named after the profile with a random prefix.

Firefox profile folder shown on disk with its random prefix

Profilin konumu aşağıdaki gibidir

  • Her Ticaretçi İçin Mükemmellik Windows > C:\Users\<username>\AppData\Roaming\Mozilla\Firefox\Profiles\profile_name.default
  • Her Ticaretçi İçin Mükemmellik Linux > ~/.mozilla/firefox/profile_name.default/
  • For Mac OS X > ~/Library/Application Support/Firefox/Profiller/profil_adı.default/

Başarılı bir çalışma yürütmek için Selenium Test, bir Firefox profil şöyle olmalıdır –

  • Yüklemesi kolay
  • Gerekirse proxy ayarları
  • Otomasyon ihtiyaçlarına göre kullanıcıya özel diğer ayarlar

Nasıl ayarlanır Firefox Şunun için profil: Selenium Testler

Let us see step by step how to create a Firefox profil.

) 1 Adım Kapat Firefox tarayıcı

In the first step, close Firefox if it is already open. The profile manager will not start while a Firefox window is running.

) 2 Adım Çalıştırmayı Aç (Windows tuşu + R) ve firefox.exe –p yazın

The Run dialog should look like the screenshot below before you press OK.

Windows Run dialog with the firefox.exe -p command typed in

Note: If it does not open you can try using full path enclosed in quotes.

  • On 32 bit Windows: “C:\Program Files\Mozilla Firefox\firefox.exe” –p
  • On 64 bit Windows (32 bit Firefox): “C:\Program Files (x86)\Mozilla Firefox\firefox.exe” –p

) 3 Adım Kullanıcı profilini seçin

Now, a dialogue box named Firefox will open, as shown below.

Firefox Choose User Profile dialogue box listing existing profiles

) 4 Adım Profil oluştur

Select the Create Profile option shown in the next screenshot to start the wizard.

Create Profile Wizard welcome screen in the Firefox profil yöneticisi

Şimdi pencereden Profil Oluştur seçeneğini seçin; bir sihirbaz açılacaktır. İleri'ye tıklayın.

) 5 Adım Profil adınızı verin

Type a name for the automation profile in the field highlighted below and finish the wizard.

Entering a new Firefox profile name in the Create Profile Wizard

Artık profiliniz hazır, profilinizi seçip açabilirsiniz Firefox. From here the profile behaves like any other browser session, so a ilk WebDriver betiği will run against it unchanged.

Yeni olduğunu fark edeceksiniz Firefox penceresi, Yer İmleriniz ve Favori simgelerinizden hiçbirini göstermez.

Note: The last selected profile, will load automatically at next Firefox öğle yemeği. Profilleri değiştirmek istiyorsanız profil yöneticisini yeniden başlatmanız gerekecektir.

Otomasyon Komut Dosyası Selenium

With the profile created, the next step is to load it from code. To access newly created Firefox profile in a Selenium WebDriver software test, we need to use WebDriver’s inbuilt class ProfilesIni and its method getProfile as shown below.

⚠️ Sürüm notu: the snippets in this section are the original Selenium 2 form. In current Selenium releases the class lives in org.openqa.selenium.firefox.ProfilesIni - .internal sub-package was dropped — and the profile is handed to the driver through FirefoxOptions. See the FirefoxOptions section below for the modern equivalent.

Selenium profil için kod

Bu, içine gömülebilecek bir profili uygulamaya yönelik bir koddur. Selenium kodu.

ProfilesIni profile = new ProfilesIni();

// bu, için bir nesne yaratacak Firefox profil

FirefoxProfile myprofile = profile.getProfile("xyzProfile");

// bu, Başlatılacak Firefox sürücü

WebDriver driver = new FirefoxDriver(myprofile)

Let us see the implementation of this code in the following examples.

Firefox Profil Örneği 1

The first example loads a profile by name. The screenshot below shows the same script inside the editor.

Firefox Profile Example 1 script loading a profile by name in the editor

// import the package
import java.io.File;
      import java.util.concurrent.TimeUnit;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class FirefoxProfile {
 	public static void main(String[] args) {
	ProfilesIni profile = new ProfilesIni();
	FirefoxProfile myprofile = profile.getProfile("xyzProfile");
// Initialize Firefox driver
	WebDriver driver = new FirefoxDriver(myprofile);
//Maximize browser window
	driver.manage().window().maximize();
//Go to URL which you want to navigate
	driver.get("http://www.google.com");
//Set  timeout  for 5 seconds so that the page may load properly within that time
	driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//close firefox browser
	driver.close();
}

}

Kodun açıklaması

Kodun satır satır açıklamasını aşağıda bulabilirsiniz.

  • Code line 2-7: First of all we need to import the package required to run the Selenium kodu.
  • Code line 8: Make a public class “FirefoxProfil."
  • Code line 9: Make an object (you need to have basic knowledge of OOPs concepts).
  • Code line 10-11: We need to initialize Firefox profile with the object of myprofile.
  • Code line 13: Create object for Firefox.
  • Code line 15: Maximize window.
  • Code line 17: driver.get is used to navigate to the given URL.
  • Code line 19: Set timeout is used to wait for some time so that browser may load the page before proceeding to next page.
  • Code line 21: Close Firefox.

Let us see one more example.

Firefox Profil Örneği 2

The second example skips profiles.ini and points at the profile folder directly, as the editor screenshot shows.

Firefox Profile Example 2 script pointing FirefoxProfile at a folder path

import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class FirefoxProfile2{
public static void main(String[] args) {

// Create object for FirefoxProfile
	FirefoxProfilemyprofile=newFirefoxProfile (newFile("\c:users\AppData\MozillaFirefoxProfile_name.default "));  
// Initialize Firefox driver    
	WebDriver driver = new FirefoxDriver(myprofile);
//Maximize browser window       
	driver.manage().window().maximize();
//Go to URL      
	driver.get("http://www.google.com");
//Set  timeout      
	driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//close firefox browser  
	driver.close();
    }

Kodun açıklaması

Kodun satır satır açıklamasını aşağıda bulabilirsiniz.

  • Code line 1-6: First of all we need to import the package required to run the Selenium kodu.
  • Code line 8: Make a public class FirefoxProfile2.
  • Code line 12: Make the object of myprofile by referring to the exact path.
  • Code line 14: Create object for Firefox.
  • Code line 16: Maximize window.
  • Code line 18: driver.get is used to navigate to the given URL.
  • Code line 20: Set timeout is used to wait for some time so that browser may load the page before proceeding to next page.
  • Code line 22: Close Firefox.

Note that the path in this snippet is written exactly as the original tutorial shows it. On a real machine the backslashes must be escaped, for example “C:\\Users\\guru99\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xyzProfile.default”.

Nasıl Kullanılır Firefox Profilleri Selenium 4 ile FirefoxSeçenekler

Both examples above compile only against Selenium 2. Two things changed afterwards, and every current tutorial uses the newer form.

  • ProfilesIni moved out of the sub-package, so the import is now org.openqa.selenium.firefox.ProfilesIni.
  • MKS FirefoxDriver(FirefoxProfile) constructor was removed. The profile is attached to a FirefoxOptions object and the options object is passed to the driver.
  • Selenium 4 timeouts take a java.time.Duration instead of a value plus a TimeUnit, so implicitlyWait(5, TimeUnit.SECONDS) becomes implicitlyWait(Duration.ofSeconds(5)).

The table below maps each legacy call to its replacement.

Legacy call (Selenium 2) Current call (Selenium 3 ve 4)
import org.openqa.selenium.firefox.internal.ProfilesIni; import org.openqa.selenium.firefox.ProfilesIni;
yeni FirefoxDriver(myprofile) options.setProfile(myprofile); new FirefoxDriver(options)
implicitlyWait(5, TimeUnit.SECONDS) implicitlyWait(Duration.ofSeconds(5))
System.setProperty for geckodriver Resolved automatically by Selenium müdür

Rewritten against a current release, Example 1 looks like this.

import java.time.Duration;
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 FirefoxProfileSelenium4 {
    public static void main(String[] args) {
        ProfilesIni allProfiles = new ProfilesIni();
        FirefoxProfile myprofile = allProfiles.getProfile("xyzProfile");

        FirefoxOptions options = new FirefoxOptions();
        options.setProfile(myprofile);

        WebDriver driver = new FirefoxDriver(options);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        driver.get("https://www.google.com");
        driver.quit();
    }
}

The profile lookup itself is unchanged: ProfilesIni still reads profiles.ini from the Firefox application-data folder and getProfile still returns null when the name does not match a profile, so a null check is worth adding before the driver starts. The same options object also carries the arguments used elsewhere, such as the ones for maximizing or resizing the browser window.

Nasıl ayarlanır Firefox Profile Preferences in Selenium

A saved profile is only half the story. Most automation needs a handful of preferences applied in code so the same behaviour follows the suite onto any machine. The setPreference method writes those values into the profile copy before Firefox başlattı.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "C:\\selenium-downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
profile.setPreference("dom.webnotifications.enabled", false);
profile.setPreference("intl.accept_languages", "es");

FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);

The preferences below cover the cases that come up most often in day-to-day scripting.

tercih Ne kontrol ediyor?
browser.download.folderList Set to 2 to use a custom download folder instead of the system default.
browser.download.dir The absolute path Firefox saves downloads into.
browser.helperApps.neverAsk.saveToDisk MIME types saved without showing the download dialog.
dom.webnotifications.enabled Set to false to suppress web push notification prompts.
intl.accept_languages The Accept-Language header, useful for localization runs.
general.useragent.geçersiz kılma Replaces the user agent string sent by the browser.

Two limits are worth knowing. Preferences must be set before the driver is created, because WebDriver copies the profile at launch and later changes are ignored. WebDriver also reserves a small set of preferences it needs in order to talk to the browser, and it overwrites those whatever you assign. Because those values live in the profile rather than in the script, they also carry across a tarayıcılar arası test run without any change to the test code.

ortak Firefox Profile Errors in Selenium ve Bunları Nasıl Düzeltebilirsiniz

Profile problems usually surface as a compile error or as a browser that opens with the wrong settings. The table lists the failures reported most often, along with what causes each one.

Semptom Sebeb olmak sabit
Yapıcı FirefoxDriver(FirefoxProfile) is undefined The constructor was removed after Selenium 2. Wrap the profile in FirefoxOptions and pass the options object instead.
Cannot resolve import org.openqa.selenium.firefox.internal.ProfilesIni The class moved out of the internal sub-package. Import org.openqa.selenium.firefox.ProfilesIni.
NullPointerException on getProfile The profile name does not match any entry in profiles.ini. Reopen the profile manager and copy the name exactly, including case.
Sizin Firefox profile cannot be loaded. It may be missing or inaccessible. Başka Firefox instance already holds the profile, or the folder path is wrong. Close every Firefox window, then verify the path against the locations listed above.
A preference has no effect It was set after the driver started, or WebDriver reserves it. Move every setPreference call above the FirefoxDriver constructor.

If the browser starts correctly but the script still fails afterwards, the profile is probably not the cause. Working through istisna işleme Selenium is usually the faster route from that point.

SSS

Hayır. FirefoxDriver never edits a pre-existing profile. It copies the profile directory into a temporary location, applies the preferences WebDriver requires, and launches the browser from that copy, so your saved bookmarks and passwords stay untouched.

Yes. Any extension installed in the profile loads with the browser. You may also call profile.addExtension(new File(“path/to/extension.xpi”)) to attach one at runtime, which keeps the on-disk profile clean.

Python has no ProfilesIni equivalent. Point FirefoxProfile at the profile directory instead, then assign it to options.profile before building the driver. The Selenium Python bindings then clone that folder exactly as Java yapar.

AI-assisted test tools compare the preferences captured on passing runs against the current profile and flag drift, such as a proxy or download folder that changed. Some frameworks also use machine learning to spot profile-related flakiness before it fails a build.

GitHub Yardımcı Pilotu generates the boilerplate quickly, but it often emits the removed FirefoxDriver(FirefoxProfile) constructor learned from older code. Always confirm the suggestion uses FirefoxOptions.setProfile and the current package before committing it.

Yes. Call options.addArguments(“-headless”) alongside options.setProfile(profile). The profile supplies preferences and extensions exactly as before, since headless mode changes only how Firefox renders, not how it reads its profile directory.

Because WebDriver works on a temporary copy and deletes it when the session ends. To keep changes, edit the profile manually in the profile manager, or set the preferences in code so every run starts from the same known state.

Not always, but it helps. Attaching the profile to FirefoxOptions ships the preferences with the capabilities payload, so a remote node applies the same downloads folder, proxy and certificate handling as your local machine does.

Bu yazıyı şu şekilde özetleyin: