We need to use DesiredCapabilities to work on new firefox(57.x) browser using selenium 3.7.1 latest version as below.
WebDriver driver;
System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir") + "/src/test/resources/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("acceptInsecureCerts", true);
capabilities.setJavascriptEnablprofile.setPreference("browser.download.useDownloadDir", true);
ed(true);
capabilities.setCapability("marionette", true);
System.setProperty("webdriver.gecko.driver","PATH TO/geckodriver.exe");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", System.getProperty("user.dir") + File.separator+ "src/test/resources/setup/test-data/temp/");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv, application/pdf, application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel, application/vnd.ms- excel,application/x-excel,application/x-msexcel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/excel,text/x-c,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/zip,application/octet-stream");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.cache.disk.enable", false);
profile.setPreference("browser.cache.memory.enable", false);
profile.setPreference("browser.cache.offline.enable", false);
profile.setPreference("network.http.use-cache", false);
profile.setPreference("pdfjs.disabled", true);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
new FirefoxOptions().setProfile(profile).addTo(capabilities);
this.driver = new FirefoxDriver(capabilities);
NOTE:
If you see above we are creating a firefox profile and passing the created firefox profile instance(3rd line) to desired capabilities and capabilities is getting passed to FirefoxDriver, so that it will help us to use all firefox profile preferences while execution.
If you want to set default systems Download directory to download files, please use below and remove above 11th line:-
profile.setPreference("browser.download.useDownloadDir", true);
All the preferences we set above will make sure our execution smoother and we don't get stuck with any download file window/popup/alerts/javascript popups when browser tries to download any files etc...
WebDriver driver;
System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir") + "/src/test/resources/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("acceptInsecureCerts", true);
capabilities.setJavascriptEnablprofile.setPreference("browser.download.useDownloadDir", true);
ed(true);
capabilities.setCapability("marionette", true);
System.setProperty("webdriver.gecko.driver","PATH TO/geckodriver.exe");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", System.getProperty("user.dir") + File.separator+ "src/test/resources/setup/test-data/temp/");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv, application/pdf, application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel, application/vnd.ms- excel,application/x-excel,application/x-msexcel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/excel,text/x-c,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/zip,application/octet-stream");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.cache.disk.enable", false);
profile.setPreference("browser.cache.memory.enable", false);
profile.setPreference("browser.cache.offline.enable", false);
profile.setPreference("network.http.use-cache", false);
profile.setPreference("pdfjs.disabled", true);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
new FirefoxOptions().setProfile(profile).addTo(capabilities);
this.driver = new FirefoxDriver(capabilities);
NOTE:
If you see above we are creating a firefox profile and passing the created firefox profile instance(3rd line) to desired capabilities and capabilities is getting passed to FirefoxDriver, so that it will help us to use all firefox profile preferences while execution.
If you want to set default systems Download directory to download files, please use below and remove above 11th line:-
profile.setPreference("browser.download.useDownloadDir", true);
All the preferences we set above will make sure our execution smoother and we don't get stuck with any download file window/popup/alerts/javascript popups when browser tries to download any files etc...
Comments
Post a Comment