public FirefoxProfile createCopy(int port) { File to = TemporaryFilesystem.createTempDir("webdriver", "profilecopy"); try { FileHandler.copy(profileDir, to); } catch (IOException e) { throw new WebDriverException( "Cannot create copy of profile " + profileDir.getAbsolutePath(), e); } FirefoxProfile profile = new FirefoxProfile(to); additionalPrefs.addTo(profile); profile.setPort(port); profile.updateUserPrefs(); return profile; } }
/** * Initialize a new profile directory, ensuring that everything is ready for use. * This contains more than we used to do - binary.startProfile(profile) is followed by * a waitFor() which waits for the start profile process to complete before calling profile * clean; moreover, we've merged in updated user prefs and port setting from elsewhere. * * @param binary the binary to initialize the profile with * @param profile the profile to be initialized * @param port the port to initialize on */ private static void initCachedProfile(FirefoxBinary binary, FirefoxProfile profile, int port) { // Install extension if necessary. profile.addWebDriverExtensionIfNeeded(false); // Set port and update user prefs. profile.setPort(port); profile.updateUserPrefs(); // Clean up the profile. try { binary.clean(profile); } catch (IOException e) { throw new WebDriverException("Unable to clean profile", e); } } }
/** * Call this to cause the current profile to be written to disk. The profile directory is * returned. Note that this profile directory is a temporary one and will be deleted when the JVM * exists (at the latest) * * This method should be called immediately before starting to use the profile and should only be * called once per instance of the {@link org.openqa.selenium.firefox.FirefoxDriver}. * * @return The directory containing the profile. */ public File layoutOnDisk() { try { File profileDir = TemporaryFilesystem.getDefaultTmpFS() .createTempDir("anonymous", "webdriver-profile"); File userPrefs = new File(profileDir, "user.js"); copyModel(model, profileDir); installExtensions(profileDir); deleteLockFiles(profileDir); deleteExtensionsCacheIfItExists(profileDir); updateUserPrefs(userPrefs); return profileDir; } catch (IOException e) { throw new UnableToCreateProfileException(e); } }