How to stop Selenium from creating temporary Firefox profiles using Web Driver?

I am using Selenium Web Driver API with Java. Every time I want to debug my test cases, a temporary profile for Firefox is created in a temporary file directory. This is a headache in two ways.

  • It definitely takes extra time to create a profile and takes up unnecessary space.
  • I can’t install any add-ons that will be available the next time I run my test cases.

How do I get around this?

+47
java firefox selenium webdriver profile
Jul 22 2018-11-11T00:
source share
10 answers

You can control how the Firefox driver selects a profile. Set the webdriver.firefox.profile property webdriver.firefox.profile name of the profile you want to use. Most people think this is a bad idea because you inherit all cookies, cache contents, etc. Previous profile uses, but this is allowed if you really want to do this.

For example:

 System.setProperty("webdriver.firefox.profile", "MySeleniumProfile"); WebDriver driver = new FirefoxDriver(...); 

UPDATE - By Ranhiru

How I processed it for Java

 FirefoxProfile profile = new FirefoxProfile(new File("D:\\Selenium Profile")); WebDriver driver = new FirefoxDriver(profile); 

Then I changed the settings in Firefox to clear all cookies and cache on exit. Take a look here on how to do this.

+31
Jul 26 '11 at 12:37
source share

Make sure you call

 driver.quit(); 

instead

 driver.close(); 

close () will not delete temporary files

+19
May 25 '15 at 11:37
source share

You can load FirefoxWebDriver using the necessary plugins by calling the addExtension(File) method in the FirefoxProfile class.

Example:

 try { File firebug = new File("C:\\FFPlugins\\firebug-1.7.3.xpi"); File xpathChecker = new File("C:\\FFPlugins\\xpath_checker-0.4.4-fx.xpi"); profile.addExtension(firebug); profile.setPreference("extensions.firebug.currentVersion", "1.7.3"); profile.addExtension(xpathChecker); profile.setPreference("extensions.xpath_checker.currentVersion", "0.4.4"); } catch(IOException e) { e.printStackTrace(); } driver = new FirefoxDriver(profile); 
+3
Apr 24 2018-12-12T00:
source share

The answer was pretty simple after I went through this question where I found the documentation. I found the FirefoxProfile class, and the constructor moved on to the Firefox profile.

 WebDriver driver = null; FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Ranhiru\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\qp1nizdo.Selenium")); driver = new FirefoxDriver(profile); 

I created a new profile by running "Firefox.exe" with the -p flag.

 Firefox.exe -p 

Installed the extensions that I need for this profile, and I was ready to go! :)

Update

It doesn't matter if you assign a profile or not, a temporary profile in the temp folder is created nonetheless. By creating and assigning a profile, you get the opportunity to use firebug / xpather / your favorite extension when testing.

+2
Jul 26 '11 at 7:11
source share

I created my own profile by running the command:

 firefox -profileManager 

(then adding any exceptions, etc. I require - as due to the clean profile of opening selenium / instance every time the exceptions are lost)

I then directly created my Firefox with this profile using the following:

 private static String profilePath = "C:\\fitnesse\\Selenesse\\FFProfiles"; private static FirefoxProfile ffprofile = new FirefoxProfile(profilePath); private static IWebDriver driver = new FirefoxDriver(ffprofile); 
+1
Apr 10 '13 at 14:37
source share

You cannot stop Selenium from creating temporary files, even if you explicitly specified it. But you can clear it after the tests are completed.

 TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles() 

Tested under MacOS and Ubuntu.

0
May 31 '13 at 17:54
source share
  • Launch firefox with: firefox -P
  • Create a new profile (e.g. webdriver1), add the necessary plugins, etc.
  • Add to your test case:

     DesiredCapabilities desiredCapabilities = new DesiredCapabilities("firefox", "", Platform.ANY); FirefoxProfile profile = new ProfilesIni().getProfile("webdriver1"); desiredCapabilities.setCapability("firefox_profile", profile); WebDriver webdriver = new RemoteWebDriver(desiredCapabilities); 
0
Jul 09 '14 at 9:49
source share

You can always use a profile called default , which is used by the user by default. There you will have all your cookies, plugins, etc., and you can use it without complications using

 System.setProperty("webdriver.firefox.profile", "default"); 

before creating webdriver

 WebDriver driver = new FirefoxDriver(); 

to create a new profile that you can execute in firefox -p shell that will show you

Add New Profile in Firefox

and get a new profile, besides the existing default . This will give you all the freedom you want.

0
Apr 29 '16 at 16:37
source share

You can tell Selenium to use a specific profile directly. Here is one example: http://automationtricks.blogspot.com/2010/05/how-to-run-test-cases-in-specified.html

-one
Jul 22 '11 at 17:36
source share

you can specify a different location for temporary files before the start of the program so that your program does not stop due to "out of memory"

 if(!new File("c:/temp_data").isDirectory()) //to check dir exist FileUtils.forceMkdir(new File("c:/temp_data")); //create dir if not exists TemporaryFilesystem.setTemporaryDirectory(new File("c:/temp_data")); //set new dir as temp file path for selenium FirefoxProfile profile = new FirefoxProfile(); 
-one
May 7 '15 at 7:11
source share



All Articles