I have a automation requirement where after a certain step a csv file needs to be downloaded and saved into a folder. In order to achieve the same ,The Firefox driver has been setup as below.
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.folderList", 2);
try
{
profile.SetPreference("browser.download.manager.showWhenStarting", false);
}
catch
{
}
profile.SetPreference("browser.download.dir", Config.I.TempDirectory);
profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
After profile has been set with required preferences. The Firefox driver was initialized as required for using the new Marionette driver
public static RemoteWebDriver GetFirefoxDriver(FirefoxProfile profile = null)
{
FirefoxDriverService firefoxService = FirefoxDriverService.CreateDefaultService();
// this should be moved to a config file.
firefoxService.FirefoxBinaryPath = Config.I.FirefoxBinaryPath;
if (profile == null)
{
var firefoxOptions = new FirefoxProfileOptions() { IsMarionette = true };
return new FirefoxDriver(firefoxService, firefoxOptions, TimeSpan.FromSeconds(20));
}
else
{
var firefoxOption = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(firefoxService, firefoxOption, TimeSpan.FromSeconds(30));
return driver;
}
}
/// <summary>
/// Extending the firefox options, so that both profile and service can be set for driver at the time of initialization,
/// Need to check whether the same needs to be here or not.
/// </summary>
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
}
The code was working properly before we upgraded to selenium 2.53.1 and Firefox 48. Any suggestions or pointers in the right direction would be of great help.