Есть 25 модулей (страниц) для каждой страницы. У меня есть 2 тестовых случая: chapterLevelTest () и PracticeLevelTese (). В каждом случае есть один метод downloadFiles (), который загружает 3 файла разных форматов. Вот код:
public void downloadFiles() throws InterruptedException {
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='data visualization']")));
Thread.sleep(500);
try {
// Crosstab Option
buttonDownload.click();
selectCrosstabOption.click();
clickDownloadOption.click();
log.info("Clicked on 'Crosstab' option to download the csv file");
//PowerPoint Option
buttonDownload.click();
selectPowerPointOption.click();
clickDownloadOption.click();
log.info("Clicked on 'PowerPoint' option to download the powerpoint file");
//Data Option
buttonDownload.click();
String parentHandle = driver.getWindowHandle(); // get the current window handle
selectDataOption.click(); // click some link that opens a new window
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
downloadAllRowsAsATextFile.click();
driver.close(); // close newly opened window when done with it
driver.switchTo().window(parentHandle);
log.info("Clicked on 'Data' option to download the csv file");
}catch (org.openqa.selenium.StaleElementReferenceException ex) {
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(buttonDownload));
}
driver.switchTo().defaultContent();
}
И вызов метода выше в тестовом примере для загрузки файлов, как показано ниже:
@ Test
public void chapterLevelTest() throws Exception
{
qualityMeasure.hoverTest();
qualityMeasure.chapterOption();
qualityMeasure.measureProgram();
qualityMeasure.lassoSelectionOfMeasures();
qualityMeasure.takeScreenshot("Quality Measure Chapter Level Image");
qualityMeasure.downloadFiles();
qualityMeasure.isFileDownloaded();
}
его файлы загрузки в расположение по умолчанию (Загрузки) Как мне загрузить его в указанном c месте. Я пробовал использовать следующий код, но у меня это не сработало. Я добавил приведенный ниже код после каждого кода варианта загрузки.
// Вариант PowerPoint
buttonDownload.click();
selectPowerPointOption.click();
clickDownloadOption.click();
log.info("Clicked on 'PowerPoint' option to download the powerpoint file");
String downloadFilepath = "C:\\Selenium\\workspace\\AHNTest\\Screenshots\\";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
Любая помощь будет принята с благодарностью !!.