From cb267dd120406d67d2fcb9a8c8cb6157f4bdd800 Mon Sep 17 00:00:00 2001 From: AutomatedOwl Date: Sat, 16 Nov 2019 01:20:31 +0200 Subject: [PATCH] Added chromeoptions for auto download. --- README.md | 2 +- pom.xml | 2 +- .../tools/SeleniumDownloadKPI.java | 31 +++++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 821ebb1..f0a9b44 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,6 @@ The method would act exactly the same as described above, just with a custom dow com.github.automatedowl selenium-download-kpi - 1.0.2 + 1.0.3 ``` diff --git a/pom.xml b/pom.xml index a141a72..ad65925 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.automatedowl selenium-download-kpi - 1.0.2 + 1.0.3 ${project.groupId}:${project.artifactId} Selenium extension for Java which provides KPIs of file downloads. https://github.com/AutomatedOwl diff --git a/src/main/java/com/github/automatedowl/tools/SeleniumDownloadKPI.java b/src/main/java/com/github/automatedowl/tools/SeleniumDownloadKPI.java index cedcb32..83dc53a 100644 --- a/src/main/java/com/github/automatedowl/tools/SeleniumDownloadKPI.java +++ b/src/main/java/com/github/automatedowl/tools/SeleniumDownloadKPI.java @@ -148,16 +148,35 @@ private static String attachDownloadBandwidth(String message) { /** @return ChromeOptions object that contained default download folder. */ public ChromeOptions generateDownloadFolderCapability() { - HashMap chromeAdditionalOptions = - new HashMap<>(); - chromeAdditionalOptions.put("download.default_directory", downloadFolder); - chromeAdditionalOptions.put("download.prompt_for_download", false); - chromeAdditionalOptions.put("download.directory_upgrade", true); + HashMap CHROME_ADDITIONAL_OPTIONS = new HashMap() {{ + put("plugins.plugins_disabled", new String[] {"Chrome PDF Viewer"}); + put("download.default_directory", downloadFolder); + put("profile.default_content_setting_values.automatic_downloads", 1); + put("profile.default_content_settings.popups", 0); + }}; ChromeOptions options = new ChromeOptions(); - options.setExperimentalOption("prefs", chromeAdditionalOptions); + options.setExperimentalOption("prefs", CHROME_ADDITIONAL_OPTIONS); return options; } + /** @return ChromeOptions object that contained default download folder. */ + public static ChromeOptions generateDownloadFolderCapability(String downloadFolder) { + HashMap CHROME_ADDITIONAL_OPTIONS = new HashMap() {{ + put("plugins.plugins_disabled", new String[] {"Chrome PDF Viewer"}); + put("download.default_directory", downloadFolder); + put("profile.default_content_setting_values.automatic_downloads", 1); + put("profile.default_content_settings.popups", 0); + }}; + + // Add chromedriver arguments. + ChromeOptions chromeOptions = new ChromeOptions(); + + // Add chrome additional options. + chromeOptions.setExperimentalOption("prefs", CHROME_ADDITIONAL_OPTIONS); + return chromeOptions; + } + + /** Calculate Mbps value from elapsed time and file size. */ private double calculateMbps(long fileSize, long startTime) { return (double)