/** * 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) * * <p>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); } }
@Test public void shouldConvertItselfIntoAMeaningfulRepresentation() throws IOException { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("i.like.cheese", true); String json = profile.toJson(); assertNotNull(json); File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("webdriver", "duplicated"); new Zip().unzip(json, dir); File prefs = new File(dir, "user.js"); assertTrue(prefs.exists()); assertTrue(FileHandler.readAsString(prefs).contains("i.like.cheese")); }
public void clean(File profileDir) { TemporaryFilesystem.getDefaultTmpFS().deleteTempDir(profileDir); }