Search code examples
javaseleniumfirefoxselenium-webdrivergeckodriver

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?


Solution

  • 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.