1

I am using Selenide framework and Java to write some automation tests. One of my tests is file download. After clicking download button Chrome gives message "This type of file can harm your computer. Do you want to keep file.xml anyway?". Is it possible to disable this? I tried below code but it does not work for me.

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("safebrowsing.enabled", "true");
options.setExperimentalOption("prefs", prefs);
ChromeDriver chromeDriver = new ChromeDriver(options);
Configuration.browser = "chrome";
4

1 回答 1

0

我找到了解决方案。我只是创建实现 WebDriverProvider 的类

public class CustomWebDriverProviderChrome implements WebDriverProvider {
    public WebDriver createDriver(DesiredCapabilities capabilities) {

        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("download.prompt_for_download", "true");
        chromePrefs.put("safebrowsing.enabled", "true");
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", chromePrefs);
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        cap.setCapability(ChromeOptions.CAPABILITY, options);

        return new ChromeDriver(cap);
    }
}
于 2017-08-24T07:59:43.220 回答