简体   繁体   中英

How can I retain my Firefox profile's cache with Geckodriver?

I need to retain my cache with Selenium and Geckodriver . I have a Firefox profile and I load it upon startup of Geckodriver :

ProfilesIni profilesIni = new ProfilesIni();
FirefoxProfile firefoxProfile = profilesIni.getProfile("profile-name");
firefoxOptions.setProfile(firefoxProfile);

This works as it is meant to, but it does not copy the cache. Going to about:cache , it's empty. I want to retain my cache, I want to use my profile directly. Currently Selenium/Geckodriver copies part of the profile and uses that, but not the cache.

How am I able to keep my cache when using Geckodriver ?

I'm using existing custom Firefox profile with this code (to be complete):

FirefoxOptions options = new FirefoxOptions();

ProfilesIni allProfiles = new ProfilesIni();         
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);

options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();

and my cache "grows" normaly.

If zero cache persists, check the setting of the Firefox profile (delete cache when closing).

Figured out the solution.

Loading the profile using this does not work:

FirefoxProfile firefoxProfile = profilesIni.getProfile("profile-name");

For me, this did however work:

String profilePath = "C\\Users\\Name\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\myprofile";
FirefoxProfile firefoxProfile = new FirefoxProfile(new File(profilePath));

I now have my correct, full cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM