I have 20 pages and each page have 2 testcases and each testcase download a number of files. I want to change the download directory for each test case at runtime.
Here is the 'TestBaseClass' code which downloading all the files in one particular folder from where I have to separate them as per category and place them into a particular folder. There are 20 folders and each folder is having 2 subfolders 'ChapterLevel' & 'PracticeLevel' in which I do have to place it manually.
Is it possible to change the download directory by passing a variable during runtime?
My TestBaseClass code:
public static WebDriver driver;
public static void initialization() throws InvocationTargetException {
    try {
        // 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\\AHNPTTest");
        // Adding cpabilities to ChromeOptions
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", prefs);
        // Launching browser with desired capabilities
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver(options);
    } 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);
}
Here is my testcase:
public class ANA_TC16_RiskAnalysisNewTest extends TestBaseClass {
    ANA_RiskAnalysisNewPage New;
    @BeforeMethod
    public void setUp() {
        try {
            initialization();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        login();
        New = new ANA_RiskAnalysisNewPage();
    }
    @Test
    public void chapterrLevelTest() throws Exception {
        New.hoverTest();
        New.clickBottomOptions();
        New.chapterOption();
        New.TopX();
        New.ATISlider();
        New.conditionSelection();
        New.takeScreenshot("Risk Analysis New Chapter Level Image");
        New.downloadOptions();
        New.isFileDownloaded();
    }
    @Test
    public void practiceLevelTest() throws Exception {
        New.hoverTest();
        New.clickBottomOptions();
        New.providerOption();
        New.TopX();
        New.ATISlider();
        New.conditionSelection();
        New.takeScreenshot("Risk Analysis New Practice Level Image");
        New.downloadOptions();
        New.isFileDownloaded();
    }
}
 
    