配置MicrosoftWebDriver以自动下载文件而无需询问

时间:2018-09-03 14:35:26

标签: selenium automation microsoft-edge

我正在使用边缘浏览器执行UI测试,并且试图将MicrosoftWebDriver配置为自动下载文件,而不问我是否要下载此文件。 在Firefox和chrome上,这段代码有效,并且我试图找到类似的内容。

FirefoxOptions options = new FirefoxOptions();
            //for downloads
            options.addPreference("browser.link.open_newwindow", 3);
            options.addPreference("browser.download.folderList", 2);
            options.addPreference("browser.download.dir", downloadDirectoryPath);
            options.addPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/pdf,audio/mpeg,image/gif,image/jpeg,image/png,text/csv,application/download");
            options.addPreference("browser.helperApps.alwaysAsk.force", false);
            options.addPreference("browser.download.manager.showWhenStarting",false);
            options.addPreference("webdriver.load.strategy", "unstable");

            //to cancel firefox extra logs
            System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
            System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");

            driver = new FirefoxDriver(options);

这是我的边缘驱动程序配置:

DesiredCapabilities capabilities = DesiredCapabilities.edge();
            capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
            capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY, "eager");
            capabilities.setPlatform(Platform.WIN10);
            capabilities.setBrowserName(BrowserType.EDGE);
            capabilities.setVersion("");
            capabilities.setCapability("browser.download.dir", downloadDirectoryPath);
            capabilities.setCapability("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/pdf,audio/mpeg,image/gif,image/jpeg,image/png,text/csv,application/download");

            driver = new EdgeDriver(capabilities);

0 个答案:

没有答案