[https://i.stack.imgur.com/Pl3Vq.png]My Scenario where 20 pages(Modules) are there. Opening each page, selecting some values from dropdown, lasso selection etc. and at last i have to click on 'Download' option, which download the image, pdf, powerpoint, crosstab and data file, Please see the image.[https://i.stack.imgur.com/wLrhB.png] which is running successfully but my issue is its downloading at default location and from there i am putting on a specific location manually for every page. I want it to download at specific location. I tried with following code which is just java class and downloading a file at specific location.
public static void main(String[] args) throws InterruptedException {
// Setting chrome driver path
System.setProperty("webdriver.chrome.driver","C:\\Users\\pdholakia\\Downloads\\Provider\\chromedriver_win32\\chromedriver.exe");
// Setting new download directory path
Map<String, Object> prefs = new HashMap<String, Object>();
// Use File.separator as it will work on any OS
prefs.put("download.default_directory", "C:\\Users\\pd\\Desktop\\AHNPTest");
// Adding cpabilities to ChromeOptions
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
// Launching browser with desired capabilities
ChromeDriver driver= new ChromeDriver(options);
// URL loading
driver.get("https://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-4.1.2-20200217.zip");
// Click on download selenium server jar file
Thread.sleep(3000);
WebElement download = driver.findElement(By.xpath("//p[2]//a[1]//strong[1]"));
Actions act = new Actions(driver);
act.moveToElement(download).click().build().perform();
}
}
But i am working with testNG framework using POM pattern. Following is my TestBaseClass which is working fine. What changes need to be done in following TestBaseClass to download the file at specific location.
public class TestBaseClass {
public static WebDriver driver;
public static void initialization() throws InvocationTargetException {
try {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}catch (Exception e) {
// generic exception handling
e.printStackTrace();
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
}
public void login() {
driver.get("https://ahnpttest.com/Account/Login");
driver.findElement(By.id("EmailAddress")).sendKeys("abc.dh@npalvinre.com");
driver.findElement(By.id("Password")).sendKeys("xyz@123");
driver.findElement(By.id("LoginButton")).click();
}
}
I replaced these 2 lines "WebDriverManager.chromedriver().setup(); driver = new ChromeDriver() of Try block of TestBaseClass by entire Download code but giving an error Null Pointer Exception.
Any help will be appreciated.