Friday, April 11, 2014

Temp File Management Using WebDriver

Here we try to handle Temp file which is generated by the WebDriver.

Q. Why we need to handle this temp file?
Ans:- It is not necessary it should be deleted automatically,but some time it may not be deleted on      different version of WebDriver, sometime it may be deleted when we quit the driver(using this line driver.quit() to quit the driver) or need to close the driver (using this line driver.close()). If we go to the User Temp(Windows +R then type %temp% to open the user temp.It is a default location to create the temp file for WebDriver) folder we see this two folder should be there after some time unzip60898411...... folder deleted and anonymous folder contains the driver files.



Q. Is there any way to change the temp folder location for WebDriver?

Ans:- Yes,we can change the temp folder location for WebDriver using this line in our code,
        TemporaryFilesystem.setTemporaryDirectory(new File("C:/xyz"));

Example:
        if(!new File("C:/XYZ").isDirectory())
        FileUtils.forceMkdir(new File("C:/XYZ"));
        TemporaryFilesystem.setTemporaryDirectory(new File("C:/xyz"));


Q. How to delete this files?

Ans:-Use this line to delete the files.

FileUtils.deleteDirectory(new File("C:/XYZ"));

Q. When we delete this files?

Ans:-We preferred to delete files at @AfterTest or @AfterClass annotation.

No comments:

Post a Comment