Open Dinh263 opened 5 years ago
Hi,
Any solution found for this issue?
Hello
Hi,
Any solution found for this issue?
Hi, The solution for above issue is:
All you can find the serenity doc : http://thucydides.info/docs/serenity/#_custom_webdriver_implementations
For detail of step 1 : use the code like below:
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
//String downloadFilepath = System.getProperty("user.dir");
prefs.put("safebrowsing.enabled", false);
prefs.put("download.default_directory", System.getProperty("user.dir")); prefs.put("download.prompt_for_download", false);
prefs.put("download.directory_upgrade", true);
prefs.put("cmd", "Page.setDownloadBehavior"); prefs.put("profile.default_content_settings.popups", 0);
prefs.put("behavior", "allow"); options.setExperimentalOption("prefs", prefs); options.addArguments("--disable-notifications");
options.addArguments("--start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-gpu");
options.addArguments("--headless");
options.addArguments("window-size=1980,1080");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--disable-extensions");
options.addArguments("--no-sandbox");
options.addArguments("--test-type");
options.addArguments("--disable-web-security");
//options.setBinary("C:\Program Files (x86)\Google\Chrome");
String chromedriverpath_1 = System.getProperty("user.dir");
String chromedriverpath = chromedriverpath_1+"//chromedriver_2_44.exe"; //System.out.println(chromedriverpath);
System.setProperty("webdriver.chrome.driver", chromedriverpath); //System.setProperty("user.dir","//chromedriver_2.44.exe");
ChromeDriverService driverService = ChromeDriverService.createDefaultService(); ChromeDriver driver = new ChromeDriver(driverService, options);
ObjectMapper objectMapper = new ObjectMapper();
HttpClient httpClient = HttpClientBuilder.create().build();
String command = null;
try {
command = objectMapper.writeValueAsString(prefs);
}
catch (JsonProcessingException e)
{ e.printStackTrace(); }
String u = driverService.getUrl().toString() + "/session/" + driver.getSessionId() + "/chromium/send_command";
HttpPost request = new HttpPost(u);
request.addHeader("content-type", "application/json");
request.setEntity(new StringEntity(command));
httpClient.execute(request);
return driver;
}
Hi, I try to download file in headless mode but it does not work. This is what i config in the serenity.property file
chrome_preferences.download.default_directory = ${user.dir}/src/test/resources/download chrome_preferences.safebrowsing.disable_download_protection = True chrome_preferences.safebrowsing.enabled = False chrome_preferences.behavior = allow
Any one has experience in download headless mode using java. Pleas help. many thanks.