Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the temporary files directory. This is a headache in two ways.

  1. It definitely is taking unnecessary time to create a profile and is taking unnecessary space.
  2. I cannot install any addons that will be available next time I launch my test cases.

How do I get around this?

like image 224
Ranhiru Jude Cooray Avatar asked Jul 22 '11 07:07

Ranhiru Jude Cooray


People also ask

How do I uninstall Firefox Selenium drivers?

You should always use driver. quit() when you want to close browser and not just one tab.

Which driver is used for Firefox automation in Selenium?

Why GeckoDriver is used? After version 47, Mozilla Firefox came out with Marionette, which is an automation driver. It remotely controls either the UI or the internal JavaScript of a Gecko platform, such as Firefox. Hence, we require GeckoDriver for Firefox.

Which driver is used for Firefox automation?

Marionette is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox.


2 Answers

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

For example:

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

UPDATE - From Ranhiru

How I handled it for Java

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

Then I changed settings in Firefox to clear all cookies and cache when exiting. Look here on how to do it.

like image 100
Ross Patterson Avatar answered Oct 05 '22 04:10

Ross Patterson


Be sure you call

driver.quit(); 

instead of

driver.close(); 

close() will not delete temporary files

like image 35
Szabolcs Filep Avatar answered Oct 05 '22 03:10

Szabolcs Filep