From dca9ea044f8145387dcbf9c09bdfd0891fa7896e Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Tue, 18 Nov 2014 13:53:35 -0500 Subject: [PATCH] Adding option to not delete anonymous Firefox profile in .NET This change adds an option to the .NET FirefoxProfile class so that the driver will not delete the anonymous profile created by the driver. Since the driver cannot and should not use an existing profile in situ because of the multiple instance automation case, this change means that modifications applied to the anonymous profile can be retained and used in future anonymous profiles.The implication is that the user can now make modifications to a profile, and retain those profile modifications (e.g., cookies) into other future profiles, simulating persistent changes over multiple browser launches. Fixes issue #7374. --- dotnet/src/webdriver/Firefox/FirefoxProfile.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Firefox/FirefoxProfile.cs b/dotnet/src/webdriver/Firefox/FirefoxProfile.cs index a43fdf020f639..79d24501f1698 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxProfile.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxProfile.cs @@ -55,6 +55,7 @@ public class FirefoxProfile private bool acceptUntrustedCerts; private bool assumeUntrustedIssuer; private bool deleteSource; + private bool deleteOnClean = true; private Preferences profilePreferences; private Dictionary extensions = new Dictionary(); #endregion @@ -116,6 +117,16 @@ public string ProfileDirectory get { return this.profileDir; } } + /// + /// Gets or sets a value indicating whether to delete this profile after use with + /// the . + /// + public bool DeleteAfterUse + { + get { return this.deleteOnClean; } + set { this.deleteOnClean = value; } + } + /// /// Gets or sets a value indicating whether native events are enabled. /// @@ -303,7 +314,7 @@ public void WriteToDisk() /// is deleted. public void Clean() { - if (!string.IsNullOrEmpty(this.profileDir) && Directory.Exists(this.profileDir)) + if (this.deleteOnClean && !string.IsNullOrEmpty(this.profileDir) && Directory.Exists(this.profileDir)) { FileUtilities.DeleteDirectory(this.profileDir); }