Opening Firefox with a Specific, non anonymous profile

This is picking up default profile even if I have provided the different profile.

I changed the line

FirefoxOptions options = new FirefoxOptions().setProfile(new FirefoxProfile());toFirefoxOptions options = new FirefoxOptions().setProfile(FF);But am getting memmory errorTest FAILED because (of) java.lang.OutOfMemoryError: Java heap space

Zeeshan Shaikh said:

This is picking up default profile even if I have provided the different profile.

I verified my code, and found the default profile seems to be picked up. I wanted to use the SeleniumFF profile. Unnn…

Zeeshan,

This is picking up default profile even if I have provided the different profile.

No. This procedure successfully picks up the different profile.

I looked at this issue a bit. My current view is as follows:

(1) The method I posted above DOES work. ProfilesIni, FirefoxProfile, FirefoxOptions, FirefoxDrivers and DriverFactory.chageDriver(driver) — this procedure successfully opens Firefox with the targeted custom profile.

(2) You can check which profile is currently applied in the Firefox-builtin “about:profiles” page. But you should be careful what exactly is displayed in the “about:profiles” page — it is misleading.

I will describe what I have found.

I made 2 Firefox profiles: usualProfile and seleniumProfile:

By clicking “start firefox” button with seleniumProfile selected, I got the following “about:profiles” page. Please note that a Green Extension icon is displayed. This Green icon indicates that Firefox is opened with seleniumProfile.

In the “firefox.exe -P” dialog I selected usualProfile.

Then, By clicking “start firefox” button with usualProfile selected, I got the following “about:profiles” page. Please note that a Red Extension icon is displayed and no Green icon there. This Red icon indicates that Firefox is opened with usualProfile.

Now, I go back to Katalon Studio, executed the following testcase:

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.internal.ProfilesIni
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
//WebUI.openBrowser('')
WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
switch(executedBrowser) {
    case WebUIDriverType.FIREFOX_DRIVER:          // "Firefox"
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile FF = profile.getProfile("seleniumProfile");
        FirefoxOptions options = new FirefoxOptions().setProfile(FF);        System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
        WebDriver driver = new FirefoxDriver(options);
        // let Katalon Studio to use the WebDriver created here
        DriverFactory.changeWebDriver(driver)
        break
}
WebUI.navigateToUrl('http://demoaut.katalon.com/')

//WebUI.closeBrowser()

Then I got the following “about:profiles” page displayed:

Please find

(1) On the top-right of the window, I find a Green extension icon. This Green icon indicates that the Firefox is opened with the seleniumProfile.

(2) However the “about:profiles” page is saying that the usualProfile is in use.
_
Inconsistent!_

I think that

(a) Firefox browser is actually opened with seleniumProfile which I specified through WebDriver call. The test case code ran successful

(b) The “about:profiles” page displays some static information which can be visualized by “firefox.exe -P” command. The “about:profiles” page shows the previous record which user profiles you clicked and selected in the UI for the last time. The “about:profiles” does not displays dynamic status which Profiles has been applied by WebDriver to the current Forefox process.

-----

So, my lesson is that “about:profiles” of Firefox does not tell me the truth (which user profile is applied) when Firefox is opened by WebDriver.

19122_i_have_2_firefox_profiles.png

19122_seleniumProfile_applied.png

19122_usualProfile_applied_2.png

19122_select_usualProfile.png

19122_Firefox_opened_by_webdriver_shows_about-profiles_page_misleading.png

Hmm I didn’t get any errors here (I’m using Katalon Studio 5.5), here is my code:

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.internal.ProfilesIni
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.driver.WebUIDriverType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
//WebUI.openBrowser('')
WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
switch(executedBrowser) {
    case WebUIDriverType.FIREFOX_DRIVER:          // "Firefox"
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile FF = profile.getProfile("SeleniumFF");
        FirefoxOptions options = new FirefoxOptions().setProfile(FF);
	System.setProperty("webdriver.firefox.bin", "/Applications/Firefox.app/Contents/MacOS/firefox")
	System.setProperty("webdriver.gecko.driver", "/Users/nguyenvinh/Desktop/Branch/5.5/Katalon Studio.app/Contents/Eclipse/configuration/resources/drivers/firefox_mac/geckodriver")
        WebDriver driver = new FirefoxDriver(options);
        // let Katalon Studio to use the WebDriver created here
        DriverFactory.changeWebDriver(driver)
        break
}
WebUI.navigateToUrl('http://demoaut.katalon.com/')
WebUI.comment('>>> opened http://demoaut.katalon.com/ in FireFox with SeleniumFF profile')
WebUI.closeBrowser()
1 Like

I used firefox profile path instead of getting firefox profile through ProfilesIni. Don’t know why but getting profiles via Ini is giving me a memory error.

WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()if (executedBrowser == WebUIDriverType.FIREFOX_DRIVER) {	KeywordUtil.logInfo("Using Firefox Profile")	FirefoxProfile FF = new FirefoxProfile(new File(GlobalVariable.firefoxProfilePath));	FirefoxOptions options = new FirefoxOptions().setProfile(FF)	WebDriver driver = new FirefoxDriver(options)	DriverFactory.changeWebDriver(driver)}else{	WebUI.openBrowser('')}

@kazurayam

Thanks for the efforts and explanation

How about inserting some debug prints for inspection?

WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()
if (executedBrowser == WebUIDriverType.FIREFOX_DRIVER) {
	KeywordUtil.logInfo("Using Firefox Profile")
	println "GlobalVariable.firefoxProfilePath=${GlobalVariable.firefoxProfilePath}"
        File profileDir = new File(GlobalVariable.firefoxProfilePath)
        assert profileDir.exists()
        assert profileDir.isDirectory()
        FirefoxProfile FF = new FirefoxProfile(profileDir)
	FirefoxOptions options = new FirefoxOptions().setProfile(FF)
        System.setProperty('webdriver.gecko.driver', DriverFactory.getGeckoDriverPath())
	WebDriver driver = new FirefoxDriver(options)
	DriverFactory.changeWebDriver(driver)
} else {
	WebUI.openBrowser('')
}

I would presume that “assert profileDir.exists()” would fail for some reason.

Using firefox profile path works fine for me.

The only issue is with getting the profile using

ProfilesIni profile = new ProfilesIni();
FirefoxProfile FF = profile.getProfile("SeleniumFF");
FirefoxOptions options = new FirefoxOptions().setProfile(FF);
1 Like

Here is the fully functional code, after some experimenting:

import org.openqa.selenium.firefox.FirefoxDriver

import org.openqa.selenium.firefox.FirefoxOptions

import org.openqa.selenium.firefox.FirefoxProfile

import org.openqa.selenium.firefox.internal.ProfilesIni

import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.webui.driver.WebUIDriverType

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// Open Browser with firefox profile UserONE

WebUI.openBrowser(’’)

WebUIDriverType executedBrowser = DriverFactory.getExecutedBrowser()

switch (executedBrowser) {

case WebUIDriverType.FIREFOX_DRIVER:

ProfilesIni profile = new ProfilesIni();

// Assume you’ve already created a profile, UserONE

FirefoxProfile FF = profile.getProfile(“UserONE”);

FirefoxOptions optionsFF = new FirefoxOptions().setProfile(FF);

WebDriver driverFF = new FirefoxDriver(optionsFF);

// Close the other opened window with the anonymous profile

WebUI.closeBrowser()

// let Katalon Studio use the WebDriver created here

DriverFactory.changeWebDriver(driverFF)

break

}

WebUI.maximizeWindow()

// Nav to url

WebUI.navigateToUrl(‘somesite.com’)

1 Like

right and can you telme how would u open about 100 diff profiles of ffox from excel or csv or database data ?

I have made and published a demo project in Github

----------

Description

How to start Firefox with prepared user profile

Have a look at the source of Test Cases/TC1

How to start Firefox with multiple user Profiles

I made a Excel book named Book1.xlsx and saved in the folder Data Files. It contains the following content: Book1

I registered the Excel file into Katalon Studio. See the document Manage Test Data

We can iterate over the list of user profile names in the data file (‘usualProfile’, ‘seleniumProfile’) in two ways.

  1. a Test Case iterates over the data while invoking another Test Case passing the profile name as parameter. Please find the code: Test Cases/TC2 iterates over the list of Profile names while calling another Test Cases/worker
  2. a Test Suite iterates over the data while invoking another Test Case passing the profile name as parameter. The following screenshot shows how Test Suites/TS3 is defined:

Both approach resulted the same output in the log:

...>>> opened http://demoaut.katalon.com/ in FireFox with profile named usualProfile...>>> opened http://demoaut.katalon.com/ in FireFox with profile named seleniumProfile...

I think this log messages proves that I could start Firefox sequentially multiple times with different customer profiles recorded in Excel file.

The Katalon documentation Data driven testing is describing similar know-how.

2 Likes

hi kazurayam
thanks for the description :slight_smile: i managed to load custom profiles using database data and add variables yesterday itself but thanks again i will test it with the method via excel posted by you .

an issue i’m facing that the firefox browsers do not fully close after completing the action successfully on a particular profile… the task ends but browser reopens and so i can see multiple browsers opened up after task completion ! say there are 5 profiles so i can see 5 browsers opened up .

thanks

any 1 ?

I have tried the above code for setting the FF profile with my ‘default’ profile. It’s working fine to run a testcase. If I didn’t specify to close the browser ( WebUI.closeBrowser()), it should continue to use the same browser for running the next testcase?
But after the testcase is done, I cannot reuse the same driver for rerunning the testcase.

Basically if I have a testsuite with 10 testcases, it will launch a new geckodriver for each testcase. Any idea how to reuse the same geckodriver and same browser for running all the testcases in the testsuite?

@kazurayam I am new to automation and trying to use your code because I need to create a non anonymous profile in order to save that sharing location is allowed and one of the imports isn’t working:

import org.openqa.selenium.firefox.internal.ProfilesIni

seems to be deprecated. Do you have any recommendations or work arounds?

import org.openqa.selenium.firefox.internal.ProfilesIni

Changing this to:

import org.openqa.selenium.firefox.ProfilesIni

will make it improved.

How did I find it? — Because the Javadoc https://selenium.dev/selenium/docs/api/java/org/openqa/selenium/firefox/internal/ProfilesIni.html sais “Use ProfilesIni instead.”

Thanks for the assist!